Compact more serde attributes

This commit is contained in:
Jonas Platte 2019-11-11 20:30:25 +01:00
parent 71fc531897
commit 4e319ae27e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
6 changed files with 22 additions and 44 deletions

View File

@ -85,13 +85,12 @@ pub struct AuthenticationData {
/// The kind of account being registered. /// The kind of account being registered.
#[derive(Copy, Clone, Debug, Deserialize, Serialize)] #[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum RegistrationKind { pub enum RegistrationKind {
/// A guest account /// A guest account
/// ///
/// These accounts may have limited permissions and may not be supported by all servers. /// These accounts may have limited permissions and may not be supported by all servers.
#[serde(rename = "guest")]
Guest, Guest,
/// A regular user account /// A regular user account
#[serde(rename = "user")]
User, User,
} }

View File

@ -9,12 +9,11 @@ use serde::{Deserialize, Serialize};
/// Format to use for returned events /// Format to use for returned events
#[derive(Copy, Clone, Debug, Deserialize, Serialize)] #[derive(Copy, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum EventFormat { pub enum EventFormat {
/// Client format, as described in the Client API. /// Client format, as described in the Client API.
#[serde(rename = "client")]
Client, Client,
/// Raw events from federation. /// Raw events from federation.
#[serde(rename = "federation")]
Federation, Federation,
} }
@ -26,15 +25,13 @@ pub struct RoomEventFilter {
/// If this list is absent then no event types are excluded. A matching type will be excluded /// If this list is absent then no event types are excluded. A matching type will be excluded
/// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any
/// sequence of characters. /// sequence of characters.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub not_types: Vec<String>, pub not_types: Vec<String>,
/// A list of room IDs to exclude. /// A list of room IDs to exclude.
/// ///
/// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// If this list is absent then no rooms are excluded. A matching room will be excluded even if
/// it is listed in the 'rooms' filter. /// it is listed in the 'rooms' filter.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
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")]
@ -42,28 +39,24 @@ pub struct RoomEventFilter {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub rooms: Option<Vec<RoomId>>, pub rooms: Option<Vec<RoomId>>,
/// A list of sender IDs to exclude. /// A list of sender IDs to exclude.
/// ///
/// If this list is absent then no senders are excluded. A matching sender will be excluded even /// If this list is absent then no senders are excluded. A matching sender will be excluded even
/// if it is listed in the 'senders' filter. /// if it is listed in the 'senders' filter.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub not_senders: Vec<UserId>, pub not_senders: Vec<UserId>,
/// 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.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub senders: Option<Vec<UserId>>, pub senders: Option<Vec<UserId>>,
/// A list of event types to include. /// A list of event types to include.
/// ///
/// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// If this list is absent then all event types are included. A '*' can be used as a wildcard to
/// match any sequence of characters. /// match any sequence of characters.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub types: Option<Vec<String>>, pub types: Option<Vec<String>>,
} }
@ -93,15 +86,13 @@ pub struct RoomFilter {
/// If this list is absent then no rooms are excluded. A matching room will be excluded even if /// If this list is absent then no rooms are excluded. A matching room will be excluded even if
/// it is listed in the 'rooms' filter. This filter is applied before the filters in /// it is listed in the 'rooms' filter. This filter is applied before the filters in
/// `ephemeral`, `state`, `timeline` or `account_data`. /// `ephemeral`, `state`, `timeline` or `account_data`.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub not_rooms: Vec<RoomId>, pub not_rooms: Vec<RoomId>,
/// A list of room IDs to include. /// A list of room IDs to include.
/// ///
/// If this list is absent then all rooms are included. This filter is applied before the /// If this list is absent then all rooms are included. This filter is applied before the
/// filters in `ephemeral`, `state`, `timeline` or `account_data`. /// filters in `ephemeral`, `state`, `timeline` or `account_data`.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub rooms: Option<Vec<RoomId>>, pub rooms: Option<Vec<RoomId>>,
} }
@ -113,8 +104,7 @@ pub struct Filter {
/// If this list is absent then no event types are excluded. A matching type will be excluded /// If this list is absent then no event types are excluded. A matching type will be excluded
/// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any /// even if it is listed in the 'types' filter. A '*' can be used as a wildcard to match any
/// sequence of characters. /// sequence of characters.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
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")]
@ -122,22 +112,19 @@ pub struct Filter {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub senders: Option<Vec<UserId>>, pub senders: Option<Vec<UserId>>,
/// A list of event types to include. /// A list of event types to include.
/// ///
/// If this list is absent then all event types are included. A '*' can be used as a wildcard to /// If this list is absent then all event types are included. A '*' can be used as a wildcard to
/// match any sequence of characters. /// match any sequence of characters.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub types: Option<Vec<String>>, pub types: Option<Vec<String>>,
/// A list of sender IDs to exclude. /// A list of sender IDs to exclude.
/// ///
/// If this list is absent then no senders are excluded. A matching sender will be excluded even /// If this list is absent then no senders are excluded. A matching sender will be excluded even
/// if it is listed in the 'senders' filter. /// if it is listed in the 'senders' filter.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub not_senders: Vec<UserId>, pub not_senders: Vec<UserId>,
} }
@ -150,8 +137,7 @@ pub struct FilterDefinition {
/// to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' /// to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content'
/// object. A literal '.' character in a field name may be escaped using a '\'. A server may /// object. A literal '.' character in a field name may be escaped using a '\'. A server may
/// include more fields than were requested. /// include more fields than were requested.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub event_fields: Option<Vec<String>>, pub event_fields: Option<Vec<String>>,
/// The format to use for events. /// The format to use for events.
/// ///

View File

@ -6,12 +6,11 @@ use serde::{Deserialize, Serialize};
/// The desired resizing method. /// The desired resizing method.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Method { pub enum Method {
/// Crop the original to produce the requested image dimensions. /// Crop the original to produce the requested image dimensions.
#[serde(rename = "crop")]
Crop, Crop,
/// Maintain the original aspect ratio of the source image. /// Maintain the original aspect ratio of the source image.
#[serde(rename = "scale")]
Scale, Scale,
} }

View File

@ -15,12 +15,10 @@ ruma_api! {
request { request {
/// A list of user IDs to remove from the list. /// A list of user IDs to remove from the list.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub drop: Vec<UserId>, pub drop: Vec<UserId>,
/// A list of user IDs to add to the list. /// A list of user IDs to add to the list.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub invite: Vec<UserId>, pub invite: Vec<UserId>,
/// The user whose presence state will be updated. /// The user whose presence state will be updated.
#[ruma_api(path)] #[ruma_api(path)]

View File

@ -21,8 +21,7 @@ ruma_api! {
/// A list of user IDs to invite to the room. /// A list of user IDs to invite to the room.
/// ///
/// This will tell the server to invite everyone in the list to the newly created room. /// This will tell the server to invite everyone in the list to the newly created room.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub invite: Vec<UserId>, pub invite: Vec<UserId>,
/// If this is included, an `m.room.name` event will be sent into the room to indicate /// If this is included, an `m.room.name` event will be sent into the room to indicate
/// the name of the room. /// the name of the room.

View File

@ -62,8 +62,7 @@ pub struct Criteria {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub include_state: Option<bool>, pub include_state: Option<bool>,
/// The keys to search for. Defaults to all keys. /// The keys to search for. Defaults to all keys.
#[serde(skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub keys: Vec<SearchKeys>, pub keys: Vec<SearchKeys>,
/// The order in which to search for results. /// The order in which to search for results.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -112,12 +111,11 @@ pub struct Grouping {
/// The key within events to use for this grouping. /// The key within events to use for this grouping.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum GroupingKey { pub enum GroupingKey {
/// `room_id` /// `room_id`
#[serde(rename = "room_id")]
RoomId, RoomId,
/// `sender` /// `sender`
#[serde(rename = "sender")]
Sender, Sender,
} }
@ -144,13 +142,12 @@ pub enum SearchKeys {
/// The order in which to search for results. /// The order in which to search for results.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum OrderBy { pub enum OrderBy {
/// Prioritize events by a numerical ranking of how closely they matched the search /// Prioritize events by a numerical ranking of how closely they matched the search
/// criteria. /// criteria.
#[serde(rename = "rank")]
Rank, Rank,
/// Prioritize recent events. /// Prioritize recent events.
#[serde(rename = "recent")]
Recent, Recent,
} }