Use js_int::uint macro for UInt constants

This commit is contained in:
Jonas Platte 2020-06-19 23:00:57 +02:00
parent c621f220b9
commit 034a9b6926
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
5 changed files with 18 additions and 21 deletions

View File

@ -1,6 +1,6 @@
//! [GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-context-eventid)
use js_int::UInt;
use js_int::{uint, UInt};
use ruma_api::ruma_api;
use ruma_events::{AnyRoomEvent, AnyStateEvent, EventJson};
use ruma_identifiers::{EventId, RoomId};
@ -75,7 +75,7 @@ ruma_api! {
}
fn default_limit() -> UInt {
UInt::from(10u32)
uint!(10)
}
#[allow(clippy::trivially_copy_pass_by_ref)]

View File

@ -1,6 +1,6 @@
//! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-messages)
use js_int::UInt;
use js_int::{uint, UInt};
use ruma_api::ruma_api;
use ruma_events::{AnyRoomEvent, AnyStateEvent, EventJson};
use ruma_identifiers::RoomId;
@ -83,7 +83,7 @@ ruma_api! {
}
fn default_limit() -> UInt {
UInt::from(10u32)
uint!(10)
}
#[allow(clippy::trivially_copy_pass_by_ref)]
@ -109,7 +109,7 @@ mod tests {
use std::convert::{TryFrom, TryInto};
use js_int::UInt;
use js_int::uint;
use ruma_identifiers::RoomId;
use crate::r0::filter::{LazyLoadOptions, RoomEventFilter};
@ -129,7 +129,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: UInt::from(0u32),
limit: uint!(0),
filter: Some(filter),
};
@ -148,7 +148,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: UInt::from(0u32),
limit: uint!(0),
filter: None,
};
@ -164,7 +164,7 @@ mod tests {
from: "token".into(),
to: Some("token2".into()),
dir: Direction::Backward,
limit: UInt::from(0u32),
limit: uint!(0),
filter: Some(RoomEventFilter::default()),
};

View File

@ -2,7 +2,7 @@
use std::collections::BTreeMap;
use js_int::UInt;
use js_int::{uint, UInt};
use ruma_api::ruma_api;
use ruma_events::{AnyEvent, AnyStateEvent, EventJson};
use ruma_identifiers::{EventId, RoomId, UserId};
@ -102,7 +102,7 @@ pub struct EventContext {
}
fn default_event_context_limit() -> UInt {
UInt::from(5u32)
uint!(5)
}
#[allow(clippy::trivially_copy_pass_by_ref)]

View File

@ -55,7 +55,7 @@ pub struct PresenceEventContent {
mod tests {
use std::convert::TryFrom;
use js_int::UInt;
use js_int::uint;
use matches::assert_matches;
use ruma_identifiers::UserId;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -69,7 +69,7 @@ mod tests {
avatar_url: Some("mxc://localhost:wefuiwegh8742w".to_string()),
currently_active: Some(false),
displayname: None,
last_active_ago: Some(UInt::try_from(2_478_593).unwrap()),
last_active_ago: Some(uint!(2_478_593)),
presence: PresenceState::Online,
status_msg: Some("Making cupcakes".to_string()),
},
@ -120,7 +120,7 @@ mod tests {
} if avatar_url == "mxc://localhost:wefuiwegh8742w"
&& status_msg == "Making cupcakes"
&& sender == "@example:localhost"
&& last_active_ago == UInt::from(2_478_593u32)
&& last_active_ago == uint!(2_478_593)
);
}
}

View File

@ -1,6 +1,6 @@
use std::convert::TryFrom;
use js_int::UInt;
use js_int::uint;
use ruma_events::{
room::{join_rules::JoinRule, topic::TopicEventContent},
AnyStateEventContent, AnyStrippedStateEventStub,
@ -100,14 +100,11 @@ fn deserialize_stripped_state_events() {
AnyStateEventContent::RoomAvatar(content) => {
let image_info = content.info.unwrap();
assert_eq!(image_info.height.unwrap(), UInt::try_from(128).unwrap());
assert_eq!(image_info.width.unwrap(), UInt::try_from(128).unwrap());
assert_eq!(image_info.height.unwrap(), uint!(128));
assert_eq!(image_info.width.unwrap(), uint!(128));
assert_eq!(image_info.mimetype.unwrap(), "image/jpeg");
assert_eq!(image_info.size.unwrap(), UInt::try_from(1024).unwrap());
assert_eq!(
image_info.thumbnail_info.unwrap().size.unwrap(),
UInt::try_from(32).unwrap()
);
assert_eq!(image_info.size.unwrap(), uint!(1024));
assert_eq!(image_info.thumbnail_info.unwrap().size.unwrap(), uint!(32));
assert_eq!(content.url, "https://example.com/image.jpg");
assert_eq!(event.state_key, "");
assert_eq!(event.sender.to_string(), "@example:localhost");