about summary refs log tree commit diff
path: root/indieauth/src/scopes.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-04-09 23:31:02 +0300
committerVika <vika@fireburn.ru>2025-04-09 23:31:57 +0300
commit8826d9446e6c492db2243b9921e59ce496027bef (patch)
tree63738aa9001cb73b11cb0e974e93129bcdf1adbb /indieauth/src/scopes.rs
parent519cadfbb298f50cbf819dde757037ab56e2863e (diff)
downloadkittybox-8826d9446e6c492db2243b9921e59ce496027bef.tar.zst
cargo fmt
Change-Id: I80e81ebba3f0cdf8c094451c9fe3ee4126b8c888
Diffstat (limited to 'indieauth/src/scopes.rs')
-rw-r--r--indieauth/src/scopes.rs78
1 files changed, 39 insertions, 39 deletions
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<str> 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<Self, Self::Err> {
-        Ok(Self(value.split_ascii_whitespace()
+        Ok(Self(
+            value
+                .split_ascii_whitespace()
                 .map(Scope::from)
-                .collect::<Vec<Scope>>()))
+                .collect::<Vec<Scope>>(),
+        ))
     }
 }
 impl Serialize for Scopes {
     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     where
-        S: Serializer
+        S: Serializer,
     {
         serializer.serialize_str(&self.to_string())
     }
@@ -163,16 +162,15 @@ impl<'de> Visitor<'de> for ScopeVisitor {
 
     fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
     where
-        E: DeserializeError
+        E: DeserializeError,
     {
         Ok(Scopes::from_str(value).unwrap())
     }
 }
 impl<'de> Deserialize<'de> for Scopes {
-
     fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
     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::<Scopes>(scope_serialized).unwrap().has_all(&scopes))
+        assert!(serde_json::from_value::<Scopes>(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")]));
     }
-
 }