diff --git a/ruma-identifiers/src/macros.rs b/ruma-identifiers/src/macros.rs index f7577d6b..fa9ed6b4 100644 --- a/ruma-identifiers/src/macros.rs +++ b/ruma-identifiers/src/macros.rs @@ -54,6 +54,14 @@ macro_rules! common_impls { } } + impl ::std::str::FromStr for $id { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + $try_from(s) + } + } + impl ::std::convert::TryFrom<&str> for $id { type Error = crate::Error; diff --git a/ruma-identifiers/src/room_version_id.rs b/ruma-identifiers/src/room_version_id.rs index 0a31c9e3..d266c9b9 100644 --- a/ruma-identifiers/src/room_version_id.rs +++ b/ruma-identifiers/src/room_version_id.rs @@ -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 { + try_from(s) + } +} + impl TryFrom<&str> for RoomVersionId { type Error = crate::Error; diff --git a/ruma-identifiers/src/server_name.rs b/ruma-identifiers/src/server_name.rs index aa401156..3923ff9d 100644 --- a/ruma-identifiers/src/server_name.rs +++ b/ruma-identifiers/src/server_name.rs @@ -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 { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + try_from(s) + } +} + impl TryFrom<&str> for Box { type Error = crate::Error;