From 7cfec8631a8eb7a93bbe0a500950db09cd5f9e24 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Jul 2020 15:51:09 +0200 Subject: [PATCH] Use the matches! macro in more places --- ruma-identifiers/Cargo.toml | 1 + ruma-identifiers/src/room_version_id.rs | 6 ++---- ruma-identifiers/src/user_id.rs | 9 +++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ruma-identifiers/Cargo.toml b/ruma-identifiers/Cargo.toml index 74a4f047..e2d89d4b 100644 --- a/ruma-identifiers/Cargo.toml +++ b/ruma-identifiers/Cargo.toml @@ -21,6 +21,7 @@ default = ["serde"] [dependencies] either = { version = "1.5.3", optional = true } +matches = "0.1.8" rand = { version = "0.7.3", optional = true } serde = { version = "1.0.113", optional = true, features = ["derive"] } strum = { version = "0.18.0", features = ["derive"] } diff --git a/ruma-identifiers/src/room_version_id.rs b/ruma-identifiers/src/room_version_id.rs index 6b5e82ea..9422a875 100644 --- a/ruma-identifiers/src/room_version_id.rs +++ b/ruma-identifiers/src/room_version_id.rs @@ -6,6 +6,7 @@ use std::{ fmt::{self, Display, Formatter}, }; +use matches::matches; #[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -91,10 +92,7 @@ impl RoomVersionId { /// Whether or not this is a custom room version. pub fn is_custom(&self) -> bool { - match self.0 { - InnerRoomVersionId::Custom(_) => true, - _ => false, - } + matches!(self.0, InnerRoomVersionId::Custom(_)) } /// Whether or not this is a version 1 room. diff --git a/ruma-identifiers/src/user_id.rs b/ruma-identifiers/src/user_id.rs index 26ec27f1..e42ff8b5 100644 --- a/ruma-identifiers/src/user_id.rs +++ b/ruma-identifiers/src/user_id.rs @@ -2,6 +2,8 @@ use std::{convert::TryFrom, num::NonZeroU8}; +use matches::matches; + use crate::{error::Error, parse_id, ServerName}; /// A Matrix user ID. @@ -116,10 +118,9 @@ pub fn localpart_is_fully_comforming(localpart: &str) -> Result { } // See https://matrix.org/docs/spec/appendices#user-identifiers - let is_fully_conforming = localpart.bytes().all(|b| match b { - b'0'..=b'9' | b'a'..=b'z' | b'-' | b'.' | b'=' | b'_' | b'/' => true, - _ => false, - }); + let is_fully_conforming = localpart + .bytes() + .all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'-' | b'.' | b'=' | b'_' | b'/')); // If it's not fully conforming, check if it contains characters that are also disallowed // for historical user IDs. If there are, return an error.