Skip to content

Commit

Permalink
federation/push: Make all pub enums non_exhaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Jul 2, 2021
1 parent 66e9bf6 commit 0a1c746
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/ruma-federation-api/src/query/get_profile_information/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ impl Response {
}

/// Profile fields to specify in query.
///
/// This type can hold an arbitrary string. To check for formats that are not available as a
/// documented variant here, use its string representation, obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[non_exhaustive]
pub enum ProfileField {
/// Display name of the user.
#[ruma_enum(rename = "displayname")]
Expand All @@ -72,3 +76,10 @@ pub enum ProfileField {
#[doc(hidden)]
_Custom(String),
}

impl ProfileField {
/// Creates a string slice from this `ProfileField`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}
11 changes: 11 additions & 0 deletions crates/ruma-push-gateway-api/src/send_event_notification/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ impl<'a> Notification<'a> {
///
/// This may be used by push gateways to deliver less time-sensitive
/// notifications in a way that will preserve battery power on mobile devices.
///
/// This type can hold an arbitrary string. To check for formats that are not available as a
/// documented variant here, use its string representation, obtained through `.as_str()`.
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum NotificationPriority {
/// A high priority notification
High,
Expand All @@ -149,6 +153,13 @@ pub enum NotificationPriority {
_Custom(String),
}

impl NotificationPriority {
/// Creates a string slice from this `NotificationPriority`.
pub fn as_str(&self) -> &str {
self.as_ref()
}
}

impl Default for NotificationPriority {
fn default() -> Self {
Self::High
Expand Down

0 comments on commit 0a1c746

Please sign in to comment.