diff options
author | Vika <vika@fireburn.ru> | 2022-07-10 20:43:24 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-07-10 20:43:24 +0300 |
commit | 0cae59373c9ab5828804477e8dedc85143ffc224 (patch) | |
tree | 70fe6cd5d9a96e83dfef9652d4986de6bf0bdd45 /kittybox-rs/indieauth | |
parent | 4fad060c009dddbe112ab09e7aa56a21ac88b0a8 (diff) | |
download | kittybox-0cae59373c9ab5828804477e8dedc85143ffc224.tar.zst |
kittybox-indieauth: implement FromStr for Scopes
Diffstat (limited to 'kittybox-rs/indieauth')
-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 { |