Debian Codegraph @

src/path/as_path.rs

raw
1 //! # as_path
2 //!
3 //! AsPath trait and implementations.
4 //!
5
6 #[cfg(test)]
7 #[path = "./as_path_test.rs"]
8 mod as_path_test;
9
10 use std::path::{Path, PathBuf};
11
12 /// Defines as path trait.
13 pub trait AsPath {
14 /// Converts to a path reference.
15 fn as_path(&self) -> &Path;
16 }
17
18 impl AsPath for str {
19 fn as_path(&self) -> &Path {
20 Path::new(self)
21 }
22 }
23
24 impl AsPath for &str {
25 fn as_path(&self) -> &Path {
26 Path::new(self)
27 }
28 }
29
30 impl AsPath for String {
31 fn as_path(&self) -> &Path {
32 Path::new(self)
33 }
34 }
35
36 impl AsPath for &String {
37 fn as_path(&self) -> &Path {
38 Path::new(self)
39 }
40 }
41
42 impl AsPath for &Path {
43 fn as_path(&self) -> &Path {
44 self
45 }
46 }
47
48 impl AsPath for PathBuf {
49 fn as_path(&self) -> &Path {
50 PathBuf::as_path(&self)
51 }
52 }