push: Add accessor for the RuleKind of Predefined{*}RuleId

This commit is contained in:
Kévin Commaille 2023-12-01 12:51:36 +01:00 committed by Kévin Commaille
parent ba75b09a45
commit 56d8a59c1b
2 changed files with 32 additions and 1 deletions

View File

@ -12,6 +12,7 @@ Improvements:
- Add `MatrixVersion::V1_9`
- Point links to the Matrix 1.9 specification
- Implement `as_str()` and `AsRef<str>` for `push::PredefinedRuleId`
- Implement `kind()` for `push::Predefined{*}RuleId`
# 0.12.1

View File

@ -6,7 +6,7 @@ use ruma_macros::StringEnum;
use super::{
Action::*, ConditionalPushRule, PatternedPushRule, PushCondition::*, RoomMemberCountIs,
Ruleset, Tweak,
RuleKind, Ruleset, Tweak,
};
use crate::{PrivOwnedStr, UserId};
@ -564,6 +564,15 @@ impl PredefinedRuleId {
Self::Content(id) => id.as_str(),
}
}
/// Get the kind of this `PredefinedRuleId`.
pub fn kind(&self) -> RuleKind {
match self {
Self::Override(id) => id.kind(),
Self::Underride(id) => id.kind(),
Self::Content(id) => id.kind(),
}
}
}
impl AsRef<str> for PredefinedRuleId {
@ -631,6 +640,13 @@ pub enum PredefinedOverrideRuleId {
_Custom(PrivOwnedStr),
}
impl PredefinedOverrideRuleId {
/// Get the kind of this `PredefinedOverrideRuleId`.
pub fn kind(&self) -> RuleKind {
RuleKind::Override
}
}
/// The rule IDs of the predefined underride server push rules.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
@ -692,6 +708,13 @@ pub enum PredefinedUnderrideRuleId {
_Custom(PrivOwnedStr),
}
impl PredefinedUnderrideRuleId {
/// Get the kind of this `PredefinedUnderrideRuleId`.
pub fn kind(&self) -> RuleKind {
RuleKind::Underride
}
}
/// The rule IDs of the predefined content server push rules.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
@ -706,6 +729,13 @@ pub enum PredefinedContentRuleId {
_Custom(PrivOwnedStr),
}
impl PredefinedContentRuleId {
/// Get the kind of this `PredefinedContentRuleId`.
pub fn kind(&self) -> RuleKind {
RuleKind::Content
}
}
#[cfg(test)]
mod tests {
use assert_matches2::assert_matches;