Skip to content

Commit

Permalink
refactor: Implement Display instead of ToString
Browse files Browse the repository at this point in the history
  • Loading branch information
Yag000 committed May 6, 2024
1 parent d944a65 commit 30b982d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/path.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
fmt::Display,
fs::read_dir,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -40,11 +41,11 @@ impl File {
}
}

impl ToString for File {
fn to_string(&self) -> String {
impl Display for File {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Image(image) => image.to_string(),
Self::Folder(folder) => folder.to_string(),
Self::Image(image) => write!(f, "{}", image),
Self::Folder(folder) => write!(f, "{}", folder),
}
}
}
Expand Down Expand Up @@ -192,9 +193,9 @@ impl ImagePath {
}
}

impl ToString for ImagePath {
fn to_string(&self) -> String {
self.path.to_str().unwrap().to_owned()
impl Display for ImagePath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.path.to_str().unwrap())
}
}

Expand Down Expand Up @@ -228,9 +229,9 @@ impl AnimtaedFolder {
}
}

impl ToString for AnimtaedFolder {
fn to_string(&self) -> String {
self.path.to_str().unwrap().to_owned()
impl Display for AnimtaedFolder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.path.to_str().unwrap())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn run(settings: Settings, action: Actions) {
Err(err) => eprintln!("Error, {}", err),
},
Actions::Get => match get_next_wallpaper(&settings) {
Ok(wallpaper) => println!("{}", wallpaper.to_string()),
Ok(wallpaper) => println!("{}", wallpaper),
Err(err) => eprintln!("Error, {}", err),
},
}
Expand Down

0 comments on commit 30b982d

Please sign in to comment.