diff options
Diffstat (limited to 'kittybox-rs')
-rw-r--r-- | kittybox-rs/indieauth/src/scopes.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/kittybox-rs/indieauth/src/scopes.rs b/kittybox-rs/indieauth/src/scopes.rs index db4778a..bc57265 100644 --- a/kittybox-rs/indieauth/src/scopes.rs +++ b/kittybox-rs/indieauth/src/scopes.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use serde::{ Serialize, Serializer, Deserialize, @@ -112,6 +114,15 @@ impl ToString for Scopes { }) } } +impl FromStr for Scopes { + type Err = std::convert::Infallible; + + fn from_str(value: &str) -> Result<Self, Self::Err> { + Ok(Self(value.split_ascii_whitespace() + .map(Scope::from) + .collect::<Vec<Scope>>())) + } +} impl Serialize for Scopes { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where @@ -132,9 +143,7 @@ impl<'de> Visitor<'de> for ScopeVisitor { where E: DeserializeError { - Ok(Scopes(value.split_ascii_whitespace() - .map(Scope::from) - .collect::<Vec<Scope>>())) + Ok(Scopes::from_str(value).unwrap()) } } impl<'de> Deserialize<'de> for Scopes { |