client-api: Make conversion from PushRule to ConditionalPushRule infallible
This commit is contained in:
parent
9b07772d1a
commit
02f29d6114
@ -1,5 +1,11 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
- The conversion from `PushRule` to `ConditionalPushRule` is infallible since
|
||||||
|
the `conditions` field is optional.
|
||||||
|
- `MissingConditionsError` was removed.
|
||||||
|
|
||||||
# 0.17.2
|
# 0.17.2
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
@ -173,32 +173,18 @@ impl TryFrom<PushRule> for PatternedPushRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that happens when `PushRule` cannot
|
impl From<PushRule> for ConditionalPushRule {
|
||||||
/// be converted into `ConditionalPushRule`
|
fn from(push_rule: PushRule) -> Self {
|
||||||
#[derive(Debug)]
|
let PushRule { actions, default, enabled, rule_id, conditions, .. } = push_rule;
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
|
||||||
pub struct MissingConditionsError;
|
|
||||||
|
|
||||||
impl fmt::Display for MissingConditionsError {
|
ConditionalPushRuleInit {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
actions,
|
||||||
write!(f, "Push rule has no conditions.")
|
default,
|
||||||
}
|
enabled,
|
||||||
}
|
rule_id,
|
||||||
|
conditions: conditions.unwrap_or_default(),
|
||||||
impl Error for MissingConditionsError {}
|
|
||||||
|
|
||||||
impl TryFrom<PushRule> for ConditionalPushRule {
|
|
||||||
type Error = MissingConditionsError;
|
|
||||||
|
|
||||||
fn try_from(push_rule: PushRule) -> Result<Self, Self::Error> {
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user