From 0cae59373c9ab5828804477e8dedc85143ffc224 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 10 Jul 2022 20:43:24 +0300 Subject: kittybox-indieauth: implement FromStr for Scopes --- kittybox-rs/indieauth/src/scopes.rs | 15 ++++++++++++--- 1 file 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 { + Ok(Self(value.split_ascii_whitespace() + .map(Scope::from) + .collect::>())) + } +} impl Serialize for Scopes { fn serialize(&self, serializer: S) -> Result where @@ -132,9 +143,7 @@ impl<'de> Visitor<'de> for ScopeVisitor { where E: DeserializeError { - Ok(Scopes(value.split_ascii_whitespace() - .map(Scope::from) - .collect::>())) + Ok(Scopes::from_str(value).unwrap()) } } impl<'de> Deserialize<'de> for Scopes { -- cgit 1.4.1