Fixup for 7b30c2b

(forgot RoomVersionId)
This commit is contained in:
Jonas Platte 2020-05-30 20:04:19 +02:00
parent cf1a1de151
commit 07040a18c8
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67

View File

@ -1,7 +1,6 @@
//! Matrix room version identifiers. //! Matrix room version identifiers.
use std::{ use std::{
borrow::Cow,
convert::TryFrom, convert::TryFrom,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
}; };
@ -187,47 +186,44 @@ impl<'de> Deserialize<'de> for RoomVersionId {
} }
} }
impl TryFrom<Cow<'_, str>> for RoomVersionId { /// Attempts to create a new Matrix room version ID from a string representation.
type Error = Error; fn try_from<S>(room_version_id: S) -> Result<RoomVersionId, Error>
where
/// Attempts to create a new Matrix room version ID from a string representation. S: AsRef<str> + Into<Box<str>>,
fn try_from(room_version_id: Cow<'_, str>) -> Result<Self, Error> { {
let version = match &room_version_id as &str { let version = match room_version_id.as_ref() {
"1" => Self(InnerRoomVersionId::Version1), "1" => RoomVersionId(InnerRoomVersionId::Version1),
"2" => Self(InnerRoomVersionId::Version2), "2" => RoomVersionId(InnerRoomVersionId::Version2),
"3" => Self(InnerRoomVersionId::Version3), "3" => RoomVersionId(InnerRoomVersionId::Version3),
"4" => Self(InnerRoomVersionId::Version4), "4" => RoomVersionId(InnerRoomVersionId::Version4),
"5" => Self(InnerRoomVersionId::Version5), "5" => RoomVersionId(InnerRoomVersionId::Version5),
custom => { custom => {
if custom.is_empty() { if custom.is_empty() {
return Err(Error::MinimumLengthNotSatisfied); return Err(Error::MinimumLengthNotSatisfied);
} else if custom.chars().count() > MAX_CODE_POINTS { } else if custom.chars().count() > MAX_CODE_POINTS {
return Err(Error::MaximumLengthExceeded); return Err(Error::MaximumLengthExceeded);
} else { } else {
Self(InnerRoomVersionId::Custom( RoomVersionId(InnerRoomVersionId::Custom(room_version_id.into()))
room_version_id.into_owned().into(),
))
}
} }
}; }
};
Ok(version) Ok(version)
}
} }
impl TryFrom<&str> for RoomVersionId { impl TryFrom<&str> for RoomVersionId {
type Error = crate::error::Error; type Error = crate::error::Error;
fn try_from(s: &str) -> Result<Self, Self::Error> { fn try_from(s: &str) -> Result<Self, Error> {
Self::try_from(Cow::Borrowed(s)) try_from(s)
} }
} }
impl TryFrom<String> for RoomVersionId { impl TryFrom<String> for RoomVersionId {
type Error = crate::error::Error; type Error = crate::error::Error;
fn try_from(s: String) -> Result<Self, Self::Error> { fn try_from(s: String) -> Result<Self, Error> {
Self::try_from(Cow::Owned(s)) try_from(s)
} }
} }