diff --git a/crates/ruma-client-api/src/push.rs b/crates/ruma-client-api/src/push.rs index 525b8a50..560a263b 100644 --- a/crates/ruma-client-api/src/push.rs +++ b/crates/ruma-client-api/src/push.rs @@ -4,8 +4,9 @@ use std::{error::Error, fmt}; pub use ruma_common::push::RuleKind; use ruma_common::{ push::{ - Action, ConditionalPushRule, ConditionalPushRuleInit, HttpPusherData, PatternedPushRule, - PatternedPushRuleInit, PushCondition, SimplePushRule, SimplePushRuleInit, + Action, AnyPushRule, AnyPushRuleRef, ConditionalPushRule, ConditionalPushRuleInit, + HttpPusherData, PatternedPushRule, PatternedPushRuleInit, PushCondition, SimplePushRule, + SimplePushRuleInit, }, serde::{JsonObject, StringEnum}, }; @@ -110,6 +111,27 @@ impl From for PushRule { } } +impl From 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> for PushRule { + fn from(push_rule: AnyPushRuleRef<'a>) -> Self { + push_rule.to_owned().into() + } +} + impl TryFrom for SimplePushRule where T: TryFrom,