identifiers: Add FromStr to MatrixUri and MatrixToUri

This commit is contained in:
Jonathan de Jong 2022-02-20 12:39:23 +01:00 committed by GitHub
parent 1db909fbc7
commit 7ca97a0f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
//! Matrix URIs. //! Matrix URIs.
use std::{convert::TryFrom, fmt}; use std::{convert::TryFrom, fmt, str::FromStr};
use percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS}; use percent_encoding::{percent_decode_str, percent_encode, AsciiSet, CONTROLS};
use ruma_identifiers_validation::{ use ruma_identifiers_validation::{
@ -306,6 +306,14 @@ impl TryFrom<&str> for MatrixToUri {
} }
} }
impl FromStr for MatrixToUri {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::parse(s)
}
}
/// The intent of a Matrix URI. /// The intent of a Matrix URI.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive] #[non_exhaustive]
@ -474,6 +482,14 @@ impl TryFrom<&str> for MatrixUri {
} }
} }
impl FromStr for MatrixUri {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::parse(s)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use matches::assert_matches; use matches::assert_matches;