From 4a926e0e64fe2091637f50bc2a0806f2b0ee8db9 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 31 Mar 2021 13:25:56 +0200 Subject: [PATCH] Consistently use `int!` macro to create `js_int::Int`s from literals --- ruma-common/src/power_levels.rs | 4 +-- ruma-events/src/room/name.rs | 4 +-- ruma-events/src/room/power_levels.rs | 52 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ruma-common/src/power_levels.rs b/ruma-common/src/power_levels.rs index e08f1611..ecc8fa64 100644 --- a/ruma-common/src/power_levels.rs +++ b/ruma-common/src/power_levels.rs @@ -2,7 +2,7 @@ //! //! [power_levels]: https://matrix.org/docs/spec/client_server/r0.6.1#m-room-power-levels -use js_int::Int; +use js_int::{int, Int}; use serde::{Deserialize, Serialize}; /// The power level requirements for specific notification types. @@ -38,5 +38,5 @@ impl Default for NotificationPowerLevels { /// Used to default power levels to 50 during deserialization. pub fn default_power_level() -> Int { - Int::from(50) + int!(50) } diff --git a/ruma-events/src/room/name.rs b/ruma-events/src/room/name.rs index e6ba33ed..71d15d4d 100644 --- a/ruma-events/src/room/name.rs +++ b/ruma-events/src/room/name.rs @@ -61,7 +61,7 @@ mod tests { time::{Duration, UNIX_EPOCH}, }; - use js_int::Int; + use js_int::int; use matches::assert_matches; use ruma_identifiers::{event_id, room_id, user_id}; use ruma_serde::Raw; @@ -109,7 +109,7 @@ mod tests { room_id: room_id!("!n8f893n9:example.com"), sender: user_id!("@carl:example.com"), state_key: "".into(), - unsigned: Unsigned { age: Some(Int::from(100)), ..Unsigned::default() }, + unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, }; let actual = to_json_value(&name_event).unwrap(); diff --git a/ruma-events/src/room/power_levels.rs b/ruma-events/src/room/power_levels.rs index 607a804f..196e1d83 100644 --- a/ruma-events/src/room/power_levels.rs +++ b/ruma-events/src/room/power_levels.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use js_int::Int; +use js_int::{int, Int}; use ruma_common::power_levels::default_power_level; use ruma_events_macros::StateEventContent; use ruma_identifiers::UserId; @@ -111,7 +111,7 @@ impl Default for PowerLevelsEventContent { /// Used with `#[serde(skip_serializing_if)]` to omit default power levels. #[allow(clippy::trivially_copy_pass_by_ref)] fn is_default_power_level(l: &Int) -> bool { - *l == Int::from(50) + *l == int!(50) } #[cfg(test)] @@ -121,7 +121,7 @@ mod tests { time::{Duration, UNIX_EPOCH}, }; - use js_int::Int; + use js_int::int; use maplit::btreemap; use ruma_identifiers::{event_id, room_id, user_id}; use serde_json::{json, to_value as to_json_value}; @@ -137,13 +137,13 @@ mod tests { content: PowerLevelsEventContent { ban: default, events: BTreeMap::new(), - events_default: Int::from(0), + events_default: int!(0), invite: default, kick: default, redact: default, state_default: default, users: BTreeMap::new(), - users_default: Int::from(0), + users_default: int!(0), notifications: NotificationPowerLevels::default(), }, event_id: event_id!("$h29iv0s8:example.com"), @@ -174,42 +174,42 @@ mod tests { let user = user_id!("@carl:example.com"); let power_levels_event = StateEvent { content: PowerLevelsEventContent { - ban: Int::from(23), + ban: int!(23), events: btreemap! { - EventType::Dummy => Int::from(23) + EventType::Dummy => int!(23) }, - events_default: Int::from(23), - invite: Int::from(23), - kick: Int::from(23), - redact: Int::from(23), - state_default: Int::from(23), + events_default: int!(23), + invite: int!(23), + kick: int!(23), + redact: int!(23), + state_default: int!(23), users: btreemap! { - user.clone() => Int::from(23) + user.clone() => int!(23) }, - users_default: Int::from(23), - notifications: NotificationPowerLevels { room: Int::from(23) }, + users_default: int!(23), + notifications: NotificationPowerLevels { room: int!(23) }, }, event_id: event_id!("$h29iv0s8:example.com"), origin_server_ts: UNIX_EPOCH + Duration::from_millis(1), prev_content: Some(PowerLevelsEventContent { // Make just one field different so we at least know they're two different objects. - ban: Int::from(42), + ban: int!(42), events: btreemap! { - EventType::Dummy => Int::from(42) + EventType::Dummy => int!(42) }, - events_default: Int::from(42), - invite: Int::from(42), - kick: Int::from(42), - redact: Int::from(42), - state_default: Int::from(42), + events_default: int!(42), + invite: int!(42), + kick: int!(42), + redact: int!(42), + state_default: int!(42), users: btreemap! { - user.clone() => Int::from(42) + user.clone() => int!(42) }, - users_default: Int::from(42), - notifications: NotificationPowerLevels { room: Int::from(42) }, + users_default: int!(42), + notifications: NotificationPowerLevels { room: int!(42) }, }), room_id: room_id!("!n8f893n9:example.com"), - unsigned: Unsigned { age: Some(Int::from(100)), ..Unsigned::default() }, + unsigned: Unsigned { age: Some(int!(100)), ..Unsigned::default() }, sender: user, state_key: "".into(), };