From bcae4e5799cbb2681c70529de2438ebcc763129b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 14 Aug 2023 15:41:15 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20Use=20.is=5Fsome=5Fand(=E2=80=A6)=20in?= =?UTF-8?q?stead=20of=20.map=5For(false,=20=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/ruma-common/src/api/metadata.rs | 11 +++++------ crates/ruma-common/src/push.rs | 8 ++++---- crates/ruma-common/src/push/condition.rs | 8 ++++---- crates/ruma-common/src/push/iter.rs | 2 +- crates/ruma-macros/src/events/event_content.rs | 2 +- crates/ruma-state-res/src/event_auth.rs | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/ruma-common/src/api/metadata.rs b/crates/ruma-common/src/api/metadata.rs index 998e76b3..08c10c6e 100644 --- a/crates/ruma-common/src/api/metadata.rs +++ b/crates/ruma-common/src/api/metadata.rs @@ -358,19 +358,18 @@ impl VersionHistory { |version: MatrixVersion| versions.iter().all(|v| v.is_superset_of(version)); // Check if all versions removed this endpoint. - if self.removed.map_or(false, greater_or_equal_all) { + if self.removed.is_some_and(greater_or_equal_all) { return VersioningDecision::Removed; } // Check if *any* version marks this endpoint as stable. - if self.added_in().map_or(false, greater_or_equal_any) { - let all_deprecated = self.deprecated.map_or(false, greater_or_equal_all); + if self.added_in().is_some_and(greater_or_equal_any) { + let all_deprecated = self.deprecated.is_some_and(greater_or_equal_all); return VersioningDecision::Stable { - any_deprecated: all_deprecated - || self.deprecated.map_or(false, greater_or_equal_any), + any_deprecated: all_deprecated || self.deprecated.is_some_and(greater_or_equal_any), all_deprecated, - any_removed: self.removed.map_or(false, greater_or_equal_any), + any_removed: self.removed.is_some_and(greater_or_equal_any), }; } diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index b24b1db8..f497834e 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -115,10 +115,10 @@ impl Ruleset { if rule_id.contains('\\') { return Err(InsertPushRuleError::InvalidRuleId); } - if after.map_or(false, |s| s.starts_with('.')) { + if after.is_some_and(|s| s.starts_with('.')) { return Err(InsertPushRuleError::RelativeToServerDefaultRule); } - if before.map_or(false, |s| s.starts_with('.')) { + if before.is_some_and(|s| s.starts_with('.')) { return Err(InsertPushRuleError::RelativeToServerDefaultRule); } @@ -291,7 +291,7 @@ impl Ruleset { ) -> Option> { let event = FlattenedJson::from_raw(event); - if event.get_str("sender").map_or(false, |sender| sender == context.user_id) { + if event.get_str("sender").is_some_and(|sender| sender == context.user_id) { // no need to look at the rules if the event was by the user themselves None } else { @@ -619,7 +619,7 @@ impl PatternedPushRule { return false; } - if event.get_str("sender").map_or(false, |sender| sender == context.user_id) { + if event.get_str("sender").is_some_and(|sender| sender == context.user_id) { return false; } diff --git a/crates/ruma-common/src/push/condition.rs b/crates/ruma-common/src/push/condition.rs index d50f454b..38c747e2 100644 --- a/crates/ruma-common/src/push/condition.rs +++ b/crates/ruma-common/src/push/condition.rs @@ -157,7 +157,7 @@ impl PushCondition { /// * `event` - The flattened JSON representation of a room message event. /// * `context` - The context of the room at the time of the event. pub fn applies(&self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool { - if event.get_str("sender").map_or(false, |sender| sender == context.user_id) { + if event.get_str("sender").is_some_and(|sender| sender == context.user_id) { return false; } @@ -198,11 +198,11 @@ impl PushCondition { } RoomVersionFeature::_Custom(_) => false, }, - Self::EventPropertyIs { key, value } => event.get(key).map_or(false, |v| v == value), + Self::EventPropertyIs { key, value } => event.get(key).is_some_and(|v| v == value), Self::EventPropertyContains { key, value } => event .get(key) .and_then(FlattenedJsonValue::as_array) - .map_or(false, |a| a.contains(value)), + .is_some_and(|a| a.contains(value)), Self::_Custom(_) => false, } } @@ -395,7 +395,7 @@ impl StrExt for str { // Look if the match has word boundaries. let word_boundary_start = !self.char_at(start).is_word_char() - || self.find_prev_char(start).map_or(true, |c| !c.is_word_char()); + || !self.find_prev_char(start).is_some_and(|c| c.is_word_char()); if word_boundary_start { let word_boundary_end = end == self.len() diff --git a/crates/ruma-common/src/push/iter.rs b/crates/ruma-common/src/push/iter.rs index bf6b75ed..aa1ad497 100644 --- a/crates/ruma-common/src/push/iter.rs +++ b/crates/ruma-common/src/push/iter.rs @@ -221,7 +221,7 @@ impl<'a> AnyPushRuleRef<'a> { /// * `event` - The flattened JSON representation of a room message event. /// * `context` - The context of the room at the time of the event. pub fn applies(self, event: &FlattenedJson, context: &PushConditionRoomCtx) -> bool { - if event.get_str("sender").map_or(false, |sender| sender == context.user_id) { + if event.get_str("sender").is_some_and(|sender| sender == context.user_id) { return false; } diff --git a/crates/ruma-macros/src/events/event_content.rs b/crates/ruma-macros/src/events/event_content.rs index f6882756..6162229e 100644 --- a/crates/ruma-macros/src/events/event_content.rs +++ b/crates/ruma-macros/src/events/event_content.rs @@ -238,7 +238,7 @@ impl TryFrom for ContentAttrs { )); } - if prefix.is_some() && !event_kind.map_or(false, |k| k.is_account_data()) { + if prefix.is_some() && !event_kind.is_some_and(|k| k.is_account_data()) { return Err(syn::Error::new_spanned( event_type, "only account data events may contain a `.*` suffix", diff --git a/crates/ruma-state-res/src/event_auth.rs b/crates/ruma-state-res/src/event_auth.rs index fab5df04..20a9373e 100644 --- a/crates/ruma-state-res/src/event_auth.rs +++ b/crates/ruma-state-res/src/event_auth.rs @@ -719,7 +719,7 @@ fn can_send_event(event: impl Event, ple: Option, user_level: Int) - return false; } - if event.state_key().map_or(false, |k| k.starts_with('@')) + if event.state_key().is_some_and(|k| k.starts_with('@')) && event.state_key() != Some(event.sender().as_str()) { return false; // permission required to post in this room