-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpaths.rs
144 lines (108 loc) · 3.66 KB
/
paths.rs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use super::prelude::*;
pub mod exports {
pub use super::{
Path,
};
}
#[ derive ( Clone ) ] // OK
#[ cfg_attr ( feature = "vonuvoli_fmt_debug", derive ( Debug ) ) ] // OK
pub struct Path ( StdRc<StdBox<fs_path::Path>> );
impl Path {
pub fn new_from_raw (path : fs_path::PathBuf, normalize : bool) -> (Path) {
if normalize && path.as_os_str () .is_empty () {
panic_0! (0xba1ee991, (github_issue, 49));
}
Path (StdRc::new (path.into_boxed_path ()))
}
pub fn new_from_buffer (path : fs_path::PathBuf, normalize : bool) -> (Path) {
Path::new_from_components (&mut path.components (), normalize)
}
pub fn new_from_ref (path : &fs_path::Path, normalize : bool) -> (Path) {
Path::new_from_components (&mut path.components (), normalize)
}
pub fn new_from_components (path : &mut dyn iter::Iterator<Item = fs_path::Component>, normalize : bool) -> (Path) {
let mut buffer = fs_path::PathBuf::new ();
for component in path {
buffer.push (component.as_os_str ());
}
Path::new_from_raw (buffer, normalize)
}
pub fn new_from_component (path : &fs_path::Component, normalize : bool) -> (Path) {
let mut buffer = fs_path::PathBuf::new ();
buffer.push (path.as_os_str ());
Path::new_from_raw (buffer, normalize)
}
pub fn new_root () -> (Path) {
Path::new_from_component (&fs_path::Component::RootDir, false)
}
pub fn new_current () -> (Path) {
Path::new_from_component (&fs_path::Component::CurDir, false)
}
pub fn new_parent () -> (Path) {
Path::new_from_component (&fs_path::Component::ParentDir, false)
}
pub fn is_absolute (&self) -> (bool) {
self.path_ref () .is_absolute ()
}
pub fn is_relative (&self) -> (bool) {
self.path_ref () .is_relative ()
}
pub fn path_ref (&self) -> (&fs_path::Path) {
&self.0
}
pub fn from_string_rc (rc : StdRc<StdBox<str>>, normalize : bool) -> (Path) {
if normalize && rc.is_empty () {
panic_0! (0x6f442154, (github_issue, 49));
}
if normalize {
FIXME! ("check if the normalized path is the same and if so keep the current `rc`");
let path = rc.deref () .deref ();
let path = fs_path::Path::new (path);
Path::new_from_ref (path, normalize)
} else {
let rc = unsafe { mem::transmute (rc) };
Path (rc)
}
}
pub fn clone_string_rc (rc : &StdRc<StdBox<str>>, normalize : bool) -> (Path) {
Path::from_string_rc (StdRc::clone (rc), normalize)
}
pub fn from_bytes_rc (rc : StdRc<StdBox<[u8]>>, normalize : bool) -> (Path) {
if normalize && rc.is_empty () {
panic_0! (0xbdff9c23, (github_issue, 49));
}
if normalize {
FIXME! ("check if the normalized path is the same and if so keep the current `rc`");
let path = rc.deref () .deref ();
let path = fs_path::Path::new (ffi::OsStr::from_bytes (path));
Path::new_from_ref (path, normalize)
} else {
let rc = unsafe { mem::transmute (rc) };
Path (rc)
}
}
pub fn clone_bytes_rc (rc : &StdRc<StdBox<[u8]>>, normalize : bool) -> (Path) {
Path::from_bytes_rc (StdRc::clone (rc), normalize)
}
pub fn from_rc (rc : StdRc<StdBox<fs_path::Path>>, normalize : bool) -> (Path) {
if normalize && rc.as_os_str () .is_empty () {
panic_0! (0xe4a2aadd, (github_issue, 49));
}
if normalize {
FIXME! ("check if the normalized path is the same and if so keep the current `rc`");
let path = &rc;
Path::new_from_ref (path, normalize)
} else {
Path (rc)
}
}
pub fn clone_rc (rc : &StdRc<StdBox<fs_path::Path>>, normalize : bool) -> (Path) {
Path::from_rc (StdRc::clone (rc), normalize)
}
pub fn is_self (&self, other : &Path) -> (bool) {
StdRc::ptr_eq (&self.0, &other.0)
}
pub fn internal_rc_clone (&self) -> (StdRc<StdBox<fs_path::Path>>) {
StdRc::clone (&self.0)
}
}