From 05badde7330063e904bb75286c14d59ed52f6550 Mon Sep 17 00:00:00 2001 From: Vika Date: Fri, 23 Aug 2024 23:43:43 +0300 Subject: kittybox-indieauth: implement Display instead of ToString --- indieauth/src/scopes.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'indieauth') 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; -- cgit 1.4.1