diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index bc19e643..5fac448e 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -1,5 +1,11 @@ # [unreleased] +Breaking changes: + +- The conversion from `PushRule` to `ConditionalPushRule` is infallible since + the `conditions` field is optional. + - `MissingConditionsError` was removed. + # 0.17.2 Improvements: diff --git a/crates/ruma-client-api/src/push.rs b/crates/ruma-client-api/src/push.rs index 560a263b..41996f5c 100644 --- a/crates/ruma-client-api/src/push.rs +++ b/crates/ruma-client-api/src/push.rs @@ -173,32 +173,18 @@ impl TryFrom for PatternedPushRule { } } -/// An error that happens when `PushRule` cannot -/// be converted into `ConditionalPushRule` -#[derive(Debug)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct MissingConditionsError; +impl From for ConditionalPushRule { + fn from(push_rule: PushRule) -> Self { + let PushRule { actions, default, enabled, rule_id, conditions, .. } = push_rule; -impl fmt::Display for MissingConditionsError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Push rule has no conditions.") - } -} - -impl Error for MissingConditionsError {} - -impl TryFrom for ConditionalPushRule { - type Error = MissingConditionsError; - - fn try_from(push_rule: PushRule) -> Result { - if let PushRule { - actions, default, enabled, rule_id, conditions: Some(conditions), .. - } = push_rule - { - Ok(ConditionalPushRuleInit { actions, default, enabled, rule_id, conditions }.into()) - } else { - Err(MissingConditionsError) + ConditionalPushRuleInit { + actions, + default, + enabled, + rule_id, + conditions: conditions.unwrap_or_default(), } + .into() } }