Add rustfmt and clippy to CI and address clippy warnings.

This commit is contained in:
Jimmy Cuadra 2019-06-02 18:14:37 -07:00
parent 21c2288d51
commit 4a4c2dd025
9 changed files with 50 additions and 14 deletions

View File

@ -1 +0,0 @@
merge_imports = true

View File

@ -1,4 +1,12 @@
language: "rust" 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: notifications:
email: false email: false
irc: irc:

View File

@ -2,7 +2,31 @@
//! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be //! endpoint in the [Matrix](https://matrix.org/) client API specification. These types can be
//! shared by client and server code. //! 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 r0;
pub mod unversioned; pub mod unversioned;

View File

@ -53,7 +53,7 @@ ruma_api! {
} }
/// Extra options to be added to the `m.room.create` event. /// 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 { pub struct CreationContent {
/// Whether users on other servers can join this room. /// Whether users on other servers can join this room.
/// ///

View File

@ -72,7 +72,7 @@ pub struct Criteria {
} }
/// Configures whether any context for the events returned are included in the response. /// 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 { 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: u64,
@ -103,7 +103,7 @@ pub struct EventContextResult {
} }
/// A grouping for partioning the result set. /// A grouping for partioning the result set.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct Grouping { pub struct Grouping {
/// The key within events to use for this grouping. /// The key within events to use for this grouping.
pub key: GroupingKey, pub key: GroupingKey,

View File

@ -53,7 +53,7 @@ ruma_api! {
} }
/// The medium of a third party identifier. /// The medium of a third party identifier.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum Medium { pub enum Medium {
/// An email address. /// An email address.
#[serde(rename = "email")] #[serde(rename = "email")]
@ -61,7 +61,7 @@ pub enum Medium {
} }
/// The authentication mechanism. /// The authentication mechanism.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum LoginType { pub enum LoginType {
/// A password is supplied to authenticate. /// A password is supplied to authenticate.
#[serde(rename = "m.login.password")] #[serde(rename = "m.login.password")]

View File

@ -52,7 +52,7 @@ ruma_api! {
} }
/// The direction to return events from. /// The direction to return events from.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum Direction { pub enum Direction {
/// Return events backwards in time from the requested `from` token. /// Return events backwards in time from the requested `from` token.
#[serde(rename = "b")] #[serde(rename = "b")]

View File

@ -57,7 +57,7 @@ ruma_api! {
} }
/// Whether to set presence or not during sync. /// Whether to set presence or not during sync.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum SetPresence { pub enum SetPresence {
/// Do not set the presence of the user calling this API. /// Do not set the presence of the user calling this API.
#[serde(rename = "offline")] #[serde(rename = "offline")]
@ -80,16 +80,18 @@ pub enum Filter {
// (there are probably some corner cases like leading whitespace) // (there are probably some corner cases like leading whitespace)
#[serde(with = "filter_def_serde")] #[serde(with = "filter_def_serde")]
/// A complete filter definition serialized to JSON. /// A complete filter definition serialized to JSON.
FilterDefinition(FilterDefinition), FilterDefinition(Box<FilterDefinition>),
/// The ID of a filter saved on the server. /// The ID of a filter saved on the server.
FilterId(String), FilterId(String),
} }
/// Serialization and deserialization logic for filter definitions.
mod filter_def_serde { mod filter_def_serde {
use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer}; use serde::{de::Error as _, ser::Error as _, Deserialize, Deserializer, Serializer};
use crate::r0::filter::FilterDefinition; use crate::r0::filter::FilterDefinition;
/// Serialization logic for filter definitions.
pub fn serialize<S>(filter_def: &FilterDefinition, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(filter_def: &FilterDefinition, serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
@ -98,12 +100,15 @@ mod filter_def_serde {
serializer.serialize_str(&string) serializer.serialize_str(&string)
} }
pub fn deserialize<'de, D>(deserializer: D) -> Result<FilterDefinition, D::Error> /// Deserialization logic for filter definitions.
pub fn deserialize<'de, D>(deserializer: D) -> Result<Box<FilterDefinition>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let filter_str = <&str>::deserialize(deserializer)?; 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 /// unread notifications count
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
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")]

View File

@ -1,4 +1,4 @@
//! Endpoints that cannot change with new versions of the Matrix specification. //! Endpoints that cannot change with new versions of the Matrix specification.
pub mod get_supported_versions;
pub mod discover_homeserver; pub mod discover_homeserver;
pub mod get_supported_versions;