diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index 7d2cf549..00000000 --- a/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -merge_imports = true diff --git a/.travis.yml b/.travis.yml index 44998ebc..e8d453d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,12 @@ language: "rust" +before_script: + - "rustup component add rustfmt" + - "rustup component add clippy" +script: + - "cargo fmt --all -- --check" + - "cargo clippy --all-targets --all-features -- -D warnings" + - "cargo build --verbose" + - "cargo test --verbose" notifications: email: false irc: diff --git a/src/lib.rs b/src/lib.rs index 86c59f30..4ca111ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,31 @@ //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! shared by client and server code. -#![deny(missing_debug_implementations, missing_docs)] +#![deny( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + warnings +)] +#![warn( + clippy::empty_line_after_outer_attr, + clippy::expl_impl_clone_on_copy, + clippy::if_not_else, + clippy::items_after_statements, + clippy::match_same_arms, + clippy::mem_forget, + clippy::missing_docs_in_private_items, + clippy::multiple_inherent_impl, + clippy::mut_mut, + clippy::needless_borrow, + clippy::needless_continue, + clippy::single_match_else, + clippy::unicode_not_nfc, + clippy::use_self, + clippy::used_underscore_binding, + clippy::wrong_pub_self_convention, + clippy::wrong_self_convention +)] pub mod r0; pub mod unversioned; diff --git a/src/r0/room/create_room.rs b/src/r0/room/create_room.rs index 8737dc10..a54f31f5 100644 --- a/src/r0/room/create_room.rs +++ b/src/r0/room/create_room.rs @@ -53,7 +53,7 @@ ruma_api! { } /// Extra options to be added to the `m.room.create` event. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct CreationContent { /// Whether users on other servers can join this room. /// diff --git a/src/r0/search/search_events.rs b/src/r0/search/search_events.rs index fd51bbcb..36814128 100644 --- a/src/r0/search/search_events.rs +++ b/src/r0/search/search_events.rs @@ -72,7 +72,7 @@ pub struct Criteria { } /// Configures whether any context for the events returned are included in the response. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct EventContext { /// How many events after the result are returned. pub after_limit: u64, @@ -103,7 +103,7 @@ pub struct EventContextResult { } /// A grouping for partioning the result set. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct Grouping { /// The key within events to use for this grouping. pub key: GroupingKey, diff --git a/src/r0/session/login.rs b/src/r0/session/login.rs index a91fb1e1..fd76156c 100644 --- a/src/r0/session/login.rs +++ b/src/r0/session/login.rs @@ -53,7 +53,7 @@ ruma_api! { } /// The medium of a third party identifier. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Medium { /// An email address. #[serde(rename = "email")] @@ -61,7 +61,7 @@ pub enum Medium { } /// The authentication mechanism. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum LoginType { /// A password is supplied to authenticate. #[serde(rename = "m.login.password")] diff --git a/src/r0/sync/get_message_events.rs b/src/r0/sync/get_message_events.rs index d378796f..1078972b 100644 --- a/src/r0/sync/get_message_events.rs +++ b/src/r0/sync/get_message_events.rs @@ -52,7 +52,7 @@ ruma_api! { } /// The direction to return events from. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum Direction { /// Return events backwards in time from the requested `from` token. #[serde(rename = "b")] diff --git a/src/r0/sync/sync_events.rs b/src/r0/sync/sync_events.rs index 4ee05169..f152ca04 100644 --- a/src/r0/sync/sync_events.rs +++ b/src/r0/sync/sync_events.rs @@ -57,7 +57,7 @@ ruma_api! { } /// Whether to set presence or not during sync. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum SetPresence { /// Do not set the presence of the user calling this API. #[serde(rename = "offline")] @@ -80,16 +80,18 @@ pub enum Filter { // (there are probably some corner cases like leading whitespace) #[serde(with = "filter_def_serde")] /// A complete filter definition serialized to JSON. - FilterDefinition(FilterDefinition), + FilterDefinition(Box), /// The ID of a filter saved on the server. FilterId(String), } +/// Serialization and deserialization logic for filter definitions. mod filter_def_serde { use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer}; use crate::r0::filter::FilterDefinition; + /// Serialization logic for filter definitions. pub fn serialize(filter_def: &FilterDefinition, serializer: S) -> Result where S: Serializer, @@ -98,12 +100,15 @@ mod filter_def_serde { serializer.serialize_str(&string) } - pub fn deserialize<'de, D>(deserializer: D) -> Result + /// Deserialization logic for filter definitions. + pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { let filter_str = <&str>::deserialize(deserializer)?; - serde_json::from_str(filter_str).map_err(D::Error::custom) + serde_json::from_str(filter_str) + .map(Box::new) + .map_err(D::Error::custom) } } @@ -147,7 +152,7 @@ pub struct JoinedRoom { } /// unread notifications count -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct UnreadNotificationsCount { /// The number of unread notifications for this room with the highlight flag set. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/unversioned.rs b/src/unversioned.rs index e77bcd06..1622a72d 100644 --- a/src/unversioned.rs +++ b/src/unversioned.rs @@ -1,4 +1,4 @@ //! Endpoints that cannot change with new versions of the Matrix specification. -pub mod get_supported_versions; pub mod discover_homeserver; +pub mod get_supported_versions;