client-api: Allow to convert AnyPushRule(Ref) to PushRule

This commit is contained in:
Kévin Commaille 2023-02-26 17:34:54 +01:00 committed by Kévin Commaille
parent ba296ec466
commit 44daf84e46

View File

@ -4,8 +4,9 @@ use std::{error::Error, fmt};
pub use ruma_common::push::RuleKind; pub use ruma_common::push::RuleKind;
use ruma_common::{ use ruma_common::{
push::{ push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, HttpPusherData, PatternedPushRule, Action, AnyPushRule, AnyPushRuleRef, ConditionalPushRule, ConditionalPushRuleInit,
PatternedPushRuleInit, PushCondition, SimplePushRule, SimplePushRuleInit, HttpPusherData, PatternedPushRule, PatternedPushRuleInit, PushCondition, SimplePushRule,
SimplePushRuleInit,
}, },
serde::{JsonObject, StringEnum}, serde::{JsonObject, StringEnum},
}; };
@ -110,6 +111,27 @@ impl From<PatternedPushRuleInit> for PushRule {
} }
} }
impl From<AnyPushRule> for PushRule {
fn from(push_rule: AnyPushRule) -> Self {
// The catch-all is unreachable if the "unstable-exhaustive-types" feature is enabled.
#[allow(unreachable_patterns)]
match push_rule {
AnyPushRule::Override(r) => r.into(),
AnyPushRule::Content(r) => r.into(),
AnyPushRule::Room(r) => r.into(),
AnyPushRule::Sender(r) => r.into(),
AnyPushRule::Underride(r) => r.into(),
_ => unreachable!(),
}
}
}
impl<'a> From<AnyPushRuleRef<'a>> for PushRule {
fn from(push_rule: AnyPushRuleRef<'a>) -> Self {
push_rule.to_owned().into()
}
}
impl<T> TryFrom<PushRule> for SimplePushRule<T> impl<T> TryFrom<PushRule> for SimplePushRule<T>
where where
T: TryFrom<String>, T: TryFrom<String>,