Use the matches! macro in more places
This commit is contained in:
parent
501652a272
commit
7cfec8631a
@ -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"] }
|
||||
|
@ -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.
|
||||
|
@ -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<bool, Error> {
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user