Debian Codegraph @

src/path/from_path.rs

raw
1 //! # from_path
2 //!
3 //! FromPath trait and implementations.
4 //!
5
6 #[cfg(test)]
7 #[path = "./from_path_test.rs"]
8 mod from_path_test;
9
10 use std::path::{Path, PathBuf};
11
12 /// Defines as path trait.
13 pub trait FromPath {
14 /// Converts from a path reference.
15 fn from_path(path: &Path) -> Self;
16 }
17
18 impl FromPath for String {
19 fn from_path(path: &Path) -> String {
20 path.to_string_lossy().into_owned()
21 }
22 }
23
24 impl FromPath for PathBuf {
25 fn from_path(path: &Path) -> PathBuf {
26 path.to_path_buf()
27 }
28 }