common: Make NotificationPowerLevels non-exhaustive

This commit is contained in:
Jonas Platte 2021-03-31 13:12:34 +02:00
parent 171fcfa965
commit d6bb977dba
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
/// The power level requirements for specific notification types. /// The power level requirements for specific notification types.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct NotificationPowerLevels { pub struct NotificationPowerLevels {
/// The level required to trigger an `@room` notification. /// The level required to trigger an `@room` notification.
#[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))] #[cfg_attr(feature = "compat", serde(deserialize_with = "ruma_serde::int_or_string_to_int"))]
@ -15,6 +16,11 @@ pub struct NotificationPowerLevels {
} }
impl NotificationPowerLevels { impl NotificationPowerLevels {
/// Create a new `NotificationPowerLevels` with all-default values.
pub fn new() -> Self {
Self { room: default_power_level() }
}
/// Value associated with the given `key`. /// Value associated with the given `key`.
pub fn get(&self, key: &str) -> Option<&Int> { pub fn get(&self, key: &str) -> Option<&Int> {
match key { match key {
@ -26,7 +32,7 @@ impl NotificationPowerLevels {
impl Default for NotificationPowerLevels { impl Default for NotificationPowerLevels {
fn default() -> Self { fn default() -> Self {
Self { room: default_power_level() } Self::new()
} }
} }