about summary refs log tree commit diff
path: root/indieauth
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-23 23:43:43 +0300
committerVika <vika@fireburn.ru>2024-08-23 23:43:43 +0300
commit05badde7330063e904bb75286c14d59ed52f6550 (patch)
tree3e0df9893a36f10fe0249760192f39752423d6a6 /indieauth
parenteb30f3bd0790fbf78aeb8cc8f33f76a0a114cc9d (diff)
downloadkittybox-05badde7330063e904bb75286c14d59ed52f6550.tar.zst
kittybox-indieauth: implement Display instead of ToString
Diffstat (limited to 'indieauth')
-rw-r--r--indieauth/src/scopes.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/indieauth/src/scopes.rs b/indieauth/src/scopes.rs
index e1df371..02ee8dc 100644
--- a/indieauth/src/scopes.rs
+++ b/indieauth/src/scopes.rs
@@ -121,19 +121,20 @@ impl AsRef<[Scope]> for Scopes {
     }
 }
 
-// Explicit implementation of ToString because of specific requirements.
-#[allow(clippy::to_string_trait_impl)]
-impl ToString for Scopes {
-    fn to_string(&self) -> String {
-        self.0.iter()
-            .map(|s| s.as_ref())
-            .fold(String::new(), |a, s| if a.is_empty() {
-                s.to_string()
-            } else {
-                a + " " + s
-            })
+impl std::fmt::Display for Scopes {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        let mut iter = self.0.iter()
+            .peekable();
+        while let Some(scope) = iter.next() {
+            f.write_str(scope.as_ref())?;
+            if iter.peek().is_some() {
+                f.write_str(" ")?;
+            }
+        }
+        Ok(())
     }
 }
+
 impl FromStr for Scopes {
     type Err = std::convert::Infallible;