diff --git a/src/format.rs b/src/format.rs index ed780f7..578e3a0 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,17 +1,6 @@ use colored::{ColoredString, Colorize, control::SHOULD_COLORIZE}; use std::path::Path; -// This trait formats a filesystem path for human-facing diagnostic output. -pub trait CodePath { - fn code_path(&self) -> ColoredString; -} - -impl CodePath for Path { - fn code_path(&self) -> ColoredString { - self.to_string_lossy().code_str() - } -} - // This trait has a function for formatting "code-like" text, such as a file path. The reason it's // implemented as a trait and not just a function is so we can use it with method syntax, as in // `x.code_str()`. Rust does not allow us to implement methods on primitive types such as `str`. @@ -31,6 +20,12 @@ impl CodeStr for str { } } +impl CodeStr for Path { + fn code_str(&self) -> ColoredString { + self.to_string_lossy().code_str() + } +} + #[cfg(test)] mod tests { use crate::format::CodeStr; diff --git a/src/run.rs b/src/run.rs index 5cf17ce..57ef645 100644 --- a/src/run.rs +++ b/src/run.rs @@ -3,9 +3,6 @@ use crate::{ format::CodeStr, state::{self, State}, }; - -#[cfg(target_os = "linux")] -use crate::format::CodePath; use byte_unit::{Byte, UnitType}; use chrono::{DateTime, Utc}; use regex::RegexSet; @@ -367,10 +364,7 @@ fn get_disk_by_file<'a>(disks: &'a [Disk], path: &Path) -> io::Result<&'a Disk> .filter(|d| path.starts_with(d.mount_point())) .max_by_key(|d| d.mount_point().as_os_str().len()) .ok_or_else(|| { - io::Error::other(format!( - "Unable to find disk for path {}.", - path.code_path(), - )) + io::Error::other(format!("Unable to find disk for path {}.", path.code_str())) }) } diff --git a/src/state.rs b/src/state.rs index 8e61857..9b0f566 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,4 @@ -use crate::format::CodePath; +use crate::format::CodeStr; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, @@ -57,7 +57,7 @@ pub fn load() -> io::Result { // Log what we are trying to do in case an error occurs. trace!( "Attempting to load the state from {}\u{2026}", - path.code_path(), + path.code_str(), ); // Read the YAML from disk. @@ -76,7 +76,7 @@ pub fn save(state: &State) -> io::Result<()> { // Check if we have a path. if let Some(path) = path() { // Log what we're trying to do in case an error occurs. - trace!("Persisting the state to {}\u{2026}", path.code_path()); + trace!("Persisting the state to {}\u{2026}", path.code_str()); // The `unwrap` is safe due to [ref:state_path_has_parent]. let parent = path.parent().unwrap().to_owned();