Implement FromStr for identifier types
This commit is contained in:
parent
dffa60d70f
commit
3454a0e750
@ -54,6 +54,14 @@ macro_rules! common_impls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ::std::str::FromStr for $id {
|
||||||
|
type Err = crate::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
$try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ::std::convert::TryFrom<&str> for $id {
|
impl ::std::convert::TryFrom<&str> for $id {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use std::{
|
|||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
fmt::{self, Display, Formatter},
|
fmt::{self, Display, Formatter},
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
@ -237,6 +238,14 @@ where
|
|||||||
Ok(version)
|
Ok(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for RoomVersionId {
|
||||||
|
type Err = crate::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Error> {
|
||||||
|
try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<&str> for RoomVersionId {
|
impl TryFrom<&str> for RoomVersionId {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use std::{
|
|||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
mem,
|
mem,
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ruma_identifiers_validation::server_name::validate;
|
use ruma_identifiers_validation::server_name::validate;
|
||||||
@ -96,6 +97,14 @@ impl<'a> TryFrom<&'a str> for &'a ServerName {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for Box<ServerName> {
|
||||||
|
type Err = crate::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<&str> for Box<ServerName> {
|
impl TryFrom<&str> for Box<ServerName> {
|
||||||
type Error = crate::Error;
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user