1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use error_stack::ResultExt; use crate::{Result, TmsError}; pub trait DirtyUtf8Path { fn to_string(&self) -> Result<String>; } impl DirtyUtf8Path for std::path::PathBuf { fn to_string(&self) -> Result<String> { Ok(self .to_str() .ok_or(TmsError::NonUtf8Path) .attach_printable("Not a valid utf8 path")? .to_string()) } } impl DirtyUtf8Path for std::path::Path { fn to_string(&self) -> Result<String> { Ok(self .to_str() .ok_or(TmsError::NonUtf8Path) .attach_printable("Not a valid utf8 path")? .to_string()) } } impl DirtyUtf8Path for std::ffi::OsStr { fn to_string(&self) -> Result<String> { Ok(self .to_str() .ok_or(TmsError::NonUtf8Path) .attach_printable("Not a valid utf8 path")? .to_string()) } }