From 8826d9446e6c492db2243b9921e59ce496027bef Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 9 Apr 2025 23:31:02 +0300 Subject: cargo fmt Change-Id: I80e81ebba3f0cdf8c094451c9fe3ee4126b8c888 --- indieauth/src/scopes.rs | 78 ++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'indieauth/src/scopes.rs') diff --git a/indieauth/src/scopes.rs b/indieauth/src/scopes.rs index 1157996..295b0c8 100644 --- a/indieauth/src/scopes.rs +++ b/indieauth/src/scopes.rs @@ -1,12 +1,8 @@ use std::str::FromStr; use serde::{ - Serialize, Serializer, - Deserialize, - de::{ - Deserializer, Visitor, - Error as DeserializeError - } + de::{Deserializer, Error as DeserializeError, Visitor}, + Deserialize, Serialize, Serializer, }; /// Various scopes that can be requested through IndieAuth. @@ -36,7 +32,7 @@ pub enum Scope { /// Allows to receive email in the profile information. Email, /// Custom scope not included above. - Custom(String) + Custom(String), } impl Scope { /// Create a custom scope from a string slice. @@ -61,25 +57,25 @@ impl AsRef for Scope { Channels => "channels", Profile => "profile", Email => "email", - Custom(s) => s.as_ref() + Custom(s) => s.as_ref(), } } } impl From<&str> for Scope { fn from(scope: &str) -> Self { match scope { - "create" => Scope::Create, - "update" => Scope::Update, - "delete" => Scope::Delete, - "media" => Scope::Media, - "read" => Scope::Read, - "follow" => Scope::Follow, - "mute" => Scope::Mute, - "block" => Scope::Block, + "create" => Scope::Create, + "update" => Scope::Update, + "delete" => Scope::Delete, + "media" => Scope::Media, + "read" => Scope::Read, + "follow" => Scope::Follow, + "mute" => Scope::Mute, + "block" => Scope::Block, "channels" => Scope::Channels, - "profile" => Scope::Profile, - "email" => Scope::Email, - other => Scope::custom(other) + "profile" => Scope::Profile, + "email" => Scope::Email, + other => Scope::custom(other), } } } @@ -106,7 +102,8 @@ impl Scopes { } /// Ensure all of the requested scopes are in the list. pub fn has_all(&self, scopes: &[Scope]) -> bool { - scopes.iter() + scopes + .iter() .map(|s1| self.iter().any(|s2| s1 == s2)) .all(|s| s) } @@ -123,8 +120,7 @@ impl AsRef<[Scope]> for Scopes { impl std::fmt::Display for Scopes { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut iter = self.0.iter() - .peekable(); + let mut iter = self.0.iter().peekable(); while let Some(scope) = iter.next() { f.write_str(scope.as_ref())?; if iter.peek().is_some() { @@ -139,15 +135,18 @@ impl FromStr for Scopes { type Err = std::convert::Infallible; fn from_str(value: &str) -> Result { - Ok(Self(value.split_ascii_whitespace() + Ok(Self( + value + .split_ascii_whitespace() .map(Scope::from) - .collect::>())) + .collect::>(), + )) } } impl Serialize for Scopes { fn serialize(&self, serializer: S) -> Result where - S: Serializer + S: Serializer, { serializer.serialize_str(&self.to_string()) } @@ -163,16 +162,15 @@ impl<'de> Visitor<'de> for ScopeVisitor { fn visit_str(self, value: &str) -> Result where - E: DeserializeError + E: DeserializeError, { Ok(Scopes::from_str(value).unwrap()) } } impl<'de> Deserialize<'de> for Scopes { - fn deserialize(deserializer: D) -> Result where - D: Deserializer<'de> + D: Deserializer<'de>, { deserializer.deserialize_str(ScopeVisitor) } @@ -185,29 +183,31 @@ mod tests { #[test] fn test_serde_vec_scope() { let scopes = vec![ - Scope::Create, Scope::Update, Scope::Delete, + Scope::Create, + Scope::Update, + Scope::Delete, Scope::Media, - Scope::custom("kittybox_internal_access") + Scope::custom("kittybox_internal_access"), ]; - let scope_serialized = serde_json::to_value( - Scopes::new(scopes.clone()) - ).unwrap(); + let scope_serialized = serde_json::to_value(Scopes::new(scopes.clone())).unwrap(); let scope_str = scope_serialized.as_str().unwrap(); - assert_eq!(scope_str, "create update delete media kittybox_internal_access"); + assert_eq!( + scope_str, + "create update delete media kittybox_internal_access" + ); - assert!(serde_json::from_value::(scope_serialized).unwrap().has_all(&scopes)) + assert!(serde_json::from_value::(scope_serialized) + .unwrap() + .has_all(&scopes)) } #[test] fn test_scope_has_all() { - let scopes = Scopes(vec![ - Scope::Create, Scope::Update, Scope::custom("draft") - ]); + let scopes = Scopes(vec![Scope::Create, Scope::Update, Scope::custom("draft")]); assert!(scopes.has_all(&[Scope::Create, Scope::custom("draft")])); assert!(!scopes.has_all(&[Scope::Read, Scope::custom("kittybox_internal_access")])); } - } -- cgit 1.4.1