From ff0338d4edeb7f617ded6c444fa571b2eca93793 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Sat, 10 Feb 2024 20:10:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Implement=20Display=20for=20Cook?= =?UTF-8?q?ie=20instead=20of=20ToString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` error: direct implementation of `ToString` --> src/bus/cookies.rs:222:1 | 222 | / impl ToString for Cookie { 223 | | fn to_string(&self) -> String { 224 | | format!("{} {} {}", self.id, self.created, self.cookie) 225 | | } 226 | | } | |_^ | = help: prefer implementing `Display` instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#to_string_trait_impl = note: `-D clippy::to-string-trait-impl` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::to_string_trait_impl)]` ``` --- src/bus/cookies.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bus/cookies.rs b/src/bus/cookies.rs index d602dcc..ca6f2ba 100644 --- a/src/bus/cookies.rs +++ b/src/bus/cookies.rs @@ -1,13 +1,14 @@ use anyhow::{anyhow, Error, Result}; use rand::Rng; -#[cfg(unix)] -use std::{fs::Permissions, os::unix::prelude::PermissionsExt}; use std::{ + fmt::{self, Display, Formatter}, io, str::FromStr, time::{Duration, SystemTime, UNIX_EPOCH}, }; #[cfg(unix)] +use std::{fs::Permissions, os::unix::prelude::PermissionsExt}; +#[cfg(unix)] use tokio::fs::set_permissions; use tokio::{ fs::{create_dir_all, metadata, remove_file, rename, File, OpenOptions}, @@ -219,9 +220,9 @@ impl FromStr for Cookie { } } -impl ToString for Cookie { - fn to_string(&self) -> String { - format!("{} {} {}", self.id, self.created, self.cookie) +impl Display for Cookie { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{} {} {}", self.id, self.created, self.cookie) } }