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 {
|
||||
type Error = crate::Error;
|
||||
|
||||
|
@ -4,6 +4,7 @@ use std::{
|
||||
cmp::Ordering,
|
||||
convert::TryFrom,
|
||||
fmt::{self, Display, Formatter},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
@ -237,6 +238,14 @@ where
|
||||
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 {
|
||||
type Error = crate::Error;
|
||||
|
||||
|
@ -4,6 +4,7 @@ use std::{
|
||||
convert::TryFrom,
|
||||
fmt::{self, Display},
|
||||
mem,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
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> {
|
||||
type Error = crate::Error;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user