Use js_int types for numbers.

See https://github.com/ruma/ruma-events/issues/27 for rationale.
This commit is contained in:
Jimmy Cuadra 2019-06-16 16:32:56 -07:00
parent 4a4c2dd025
commit a16eb7cfe1
14 changed files with 44 additions and 27 deletions

View File

@ -12,20 +12,24 @@ version = "0.3.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
futures = "0.1.26" futures = "0.1.27"
http = "0.1.17" http = "0.1.17"
hyper = "0.12.27" hyper = "0.12.29"
ruma-api = "0.7.0" ruma-api = "0.8.0"
ruma-api-macros = "0.4.0" ruma-api-macros = "0.5.0"
ruma-events = "0.12.0" ruma-events = "0.12.0"
ruma-identifiers = "0.12.0" ruma-identifiers = "0.13.0"
ruma-signatures = "0.4.2" ruma-signatures = "0.4.2"
serde_json = "1.0.39" serde_json = "1.0.39"
serde_urlencoded = "0.5.4" serde_urlencoded = "0.5.5"
url_serde = "0.2.0" url_serde = "0.2.0"
[dependencies.js_int]
version = "0.1.0"
features = ["serde"]
[dependencies.serde] [dependencies.serde]
version = "1.0.90" version = "1.0.92"
features = ["derive"] features = ["derive"]
[dependencies.url] [dependencies.url]

View File

@ -1,5 +1,6 @@
//! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken) //! [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-password-email-requesttoken)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -22,7 +23,7 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub id_server: Option<String>, pub id_server: Option<String>,
/// TODO: This parameter is not documented in the spec. /// TODO: This parameter is not documented in the spec.
pub send_attempt: u64, pub send_attempt: UInt,
} }
response {} response {}

View File

@ -1,5 +1,6 @@
//! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken) //! [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-register-email-requesttoken)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -22,7 +23,7 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub id_server: Option<String>, pub id_server: Option<String>,
/// Used to distinguish protocol level retries from requests to re-send the email. /// Used to distinguish protocol level retries from requests to re-send the email.
pub send_attempt: u64, pub send_attempt: UInt,
} }
response {} response {}

View File

@ -1,5 +1,6 @@
//! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken) //! [POST /_matrix/client/r0/account/3pid/email/requestToken](https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-account-3pid-email-requesttoken)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -22,7 +23,7 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub id_server: Option<String>, pub id_server: Option<String>,
/// Used to distinguish protocol level retries from requests to re-send the email. /// Used to distinguish protocol level retries from requests to re-send the email.
pub send_attempt: u64, pub send_attempt: UInt,
} }
response {} response {}

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms) //! [GET /_matrix/client/r0/publicRooms](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-publicrooms)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomAliasId, RoomId}; use ruma_identifiers::{RoomAliasId, RoomId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -43,7 +44,7 @@ pub struct PublicRoomsChunk {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>, pub name: Option<String>,
/// The number of members joined to the room. /// The number of members joined to the room.
pub num_joined_members: u64, pub num_joined_members: UInt,
/// The ID of the room. /// The ID of the room.
pub room_id: RoomId, pub room_id: RoomId,
/// The topic of the room, if any. /// The topic of the room, if any.

View File

@ -3,6 +3,7 @@
pub mod create_filter; pub mod create_filter;
pub mod get_filter; pub mod get_filter;
use js_int::UInt;
use ruma_identifiers::{RoomId, UserId}; use ruma_identifiers::{RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -37,7 +38,7 @@ pub struct RoomEventFilter {
pub not_rooms: Vec<String>, pub not_rooms: Vec<String>,
/// The maximum number of events to return. /// The maximum number of events to return.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>, pub limit: Option<UInt>,
/// A list of room IDs to include. /// A list of room IDs to include.
/// ///
/// If this list is absent then all rooms are included. /// If this list is absent then all rooms are included.
@ -117,7 +118,7 @@ pub struct Filter {
pub not_types: Vec<String>, pub not_types: Vec<String>,
/// The maximum number of events to return. /// The maximum number of events to return.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>, pub limit: Option<UInt>,
/// A list of senders IDs to include. /// A list of senders IDs to include.
/// ///
/// If this list is absent then all senders are included. /// If this list is absent then all senders are included.

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid) //! [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-media-r0-thumbnail-servername-mediaid)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -34,14 +35,14 @@ ruma_api! {
/// The *desired* height of the thumbnail. The actual thumbnail may not match the size /// The *desired* height of the thumbnail. The actual thumbnail may not match the size
/// specified. /// specified.
#[ruma_api(query)] #[ruma_api(query)]
pub height: Option<u64>, pub height: Option<UInt>,
/// The desired resizing method. /// The desired resizing method.
#[ruma_api(query)] #[ruma_api(query)]
pub method: Option<Method>, pub method: Option<Method>,
/// The *desired* width of the thumbnail. The actual thumbnail may not match the size /// The *desired* width of the thumbnail. The actual thumbnail may not match the size
/// specified. /// specified.
#[ruma_api(query)] #[ruma_api(query)]
pub width: Option<u64>, pub width: Option<UInt>,
} }
response { response {

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status) //! [GET /_matrix/client/r0/presence/{userId}/status](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-presence-userid-status)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_events::presence::PresenceState; use ruma_events::presence::PresenceState;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
@ -30,7 +31,7 @@ ruma_api! {
pub currently_active: Option<bool>, pub currently_active: Option<bool>,
/// The length of time in milliseconds since an action was performed by the user. /// The length of time in milliseconds since an action was performed by the user.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub last_active_ago: Option<u64>, pub last_active_ago: Option<UInt>,
/// The user's presence state. /// The user's presence state.
pub presence: PresenceState, pub presence: PresenceState,
} }

View File

@ -2,6 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_events::collections::all::Event; use ruma_events::collections::all::Event;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
@ -75,9 +76,9 @@ pub struct Criteria {
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct EventContext { pub struct EventContext {
/// How many events after the result are returned. /// How many events after the result are returned.
pub after_limit: u64, pub after_limit: UInt,
/// How many events before the result are returned. /// How many events before the result are returned.
pub before_limit: u64, pub before_limit: UInt,
/// Requests that the server returns the historic profile information for the users that /// Requests that the server returns the historic profile information for the users that
/// sent the events that were returned. /// sent the events that were returned.
pub include_profile: bool, pub include_profile: bool,
@ -165,7 +166,7 @@ pub struct ResultCategories {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RoomEventResults { pub struct RoomEventResults {
/// An approximate count of the total number of results found. /// An approximate count of the total number of results found.
pub count: u64, pub count: UInt,
/// Any groups that were requested. /// Any groups that were requested.
// TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773 // TODO: Not sure this is right. https://github.com/matrix-org/matrix-doc/issues/773
pub groups: HashMap<GroupingKey, HashMap<RoomId, ResultGroup>>, pub groups: HashMap<GroupingKey, HashMap<RoomId, ResultGroup>>,
@ -191,7 +192,7 @@ pub struct ResultGroup {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub next_batch: Option<String>, pub next_batch: Option<String>,
/// Key that can be used to order different groups. /// Key that can be used to order different groups.
pub order: u64, pub order: UInt,
/// Which results are in this group. /// Which results are in this group.
pub results: Vec<EventId>, pub results: Vec<EventId>,
} }

View File

@ -2,6 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -36,7 +37,7 @@ pub struct ConnectionInfo {
/// Most recently seen IP address of the session. /// Most recently seen IP address of the session.
pub ip: String, pub ip: String,
/// Unix timestamp that the session was last active. /// Unix timestamp that the session was last active.
pub last_seen: u64, pub last_seen: UInt,
/// User agent string last seen in the session. /// User agent string last seen in the session.
pub user_agent: String, pub user_agent: String,
} }

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages) //! [GET /_matrix/client/r0/rooms/{roomId}/messages](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-rooms-roomid-messages)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_events::collections::only; use ruma_events::collections::only;
use ruma_identifiers::RoomId; use ruma_identifiers::RoomId;
@ -38,7 +39,7 @@ ruma_api! {
/// ///
/// Default: 10. /// Default: 10.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>, pub limit: Option<UInt>,
} }
response { response {

View File

@ -2,6 +2,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_events::{ use ruma_events::{
collections::{all, only}, collections::{all, only},
@ -42,7 +43,7 @@ ruma_api! {
/// The maximum time to poll in milliseconds before returning this request. /// The maximum time to poll in milliseconds before returning this request.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
#[ruma_api(query)] #[ruma_api(query)]
pub timeout: Option<u64>, pub timeout: Option<UInt>,
} }
response { response {
@ -156,10 +157,10 @@ pub struct JoinedRoom {
pub struct UnreadNotificationsCount { pub struct UnreadNotificationsCount {
/// The number of unread notifications for this room with the highlight flag set. /// The number of unread notifications for this room with the highlight flag set.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub highlight_count: Option<u64>, pub highlight_count: Option<UInt>,
/// The total number of unread notifications for this room. /// The total number of unread notifications for this room.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub notification_count: Option<u64>, pub notification_count: Option<UInt>,
} }
/// Events in the room. /// Events in the room.

View File

@ -1,5 +1,6 @@
//! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid) //! [PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}](https://matrix.org/docs/spec/client_server/r0.4.0.html#put-matrix-client-r0-rooms-roomid-typing-userid)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use ruma_identifiers::{RoomId, UserId}; use ruma_identifiers::{RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -20,7 +21,7 @@ ruma_api! {
pub room_id: RoomId, pub room_id: RoomId,
/// The length of time in milliseconds to mark this user as typing. /// The length of time in milliseconds to mark this user as typing.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<u64>, pub timeout: Option<UInt>,
/// Whether the user is typing or not. If `false`, the `timeout` key can be omitted. /// Whether the user is typing or not. If `false`, the `timeout` key can be omitted.
pub typing: bool, pub typing: bool,
/// The user who has started to type. /// The user who has started to type.

View File

@ -1,5 +1,6 @@
//! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver) //! [GET /_matrix/client/r0/voip/turnServer](https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-voip-turnserver)
use js_int::UInt;
use ruma_api_macros::ruma_api; use ruma_api_macros::ruma_api;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -19,7 +20,7 @@ ruma_api! {
/// The password to use. /// The password to use.
pub password: String, pub password: String,
/// The time-to-live in seconds. /// The time-to-live in seconds.
pub ttl: u64, pub ttl: UInt,
/// A list of TURN URIs. /// A list of TURN URIs.
pub uris: Vec<String>, pub uris: Vec<String>,
/// The username to use. /// The username to use.