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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//! Type aliases and trait definitions for internal traits - **instantiated twice**
//!
//! Like `funcs`, this is instantiated twice, as
//! [`crate::strings::wtraits`] and [`crate::path::wtraits`].
//!
//! He type aliases, and even traits, here,
//! are all different, in the two contexts.
pub use Cow;
pub use fmt;
pub use PathBuf;
/// External borrowed form; inputs are generally of type `AsRef<Xstr>`
///
/// `str` for strings; [`Path`](std::path::Path) for paths.
pub type Xstr = Xstr;
/// Working, possibly-owned, form of the input
///
/// Usually converted from `AsRef<`[`Xstr`]`>`,
/// using [`.into_winput()`](AsRefXstrExt::into_winput).
///
/// For strings, this is simply `&'s str`;
///
/// For paths, this is `Cow<'s, RawOsStr>`.
/// This is because it can be necessary to copy-convert the input
/// to a different representation.
/// (This happens only on Windows, whose native character encoding UTF-16, which is deranged;
/// on Unix, I believe this is always `Cow::Borrowed`.)
pub type WInput<'s> = WInput;
/// Working, definitely-borrowed, form of the input
///
/// Most input-processing, such as slicing up the input, is done with this type.
///
/// `str` for strings, `RawOsStr` for paths.
pub type Wstr = Wstr;
/// Output accumulator (owned)
///
/// As we process input chunks, we add them to this.
///
/// This type doesn't provide an easy way to rescan it again -
/// but we generally only want to scan things once.
///
/// Also used for error reporting, in `LookupError`.
///
/// `String`, or [`OsString`](std::ffi::OsString).
pub type OString = OString;
/// Owned version of Xstr
///
/// `String`, or `PathBuf`.
///
/// Currently used only as the return value from `home_dir()`.
pub type XString = Owned;
/// Extra bounds on [`Xstr`] (and hence, restrictions on [`XString`])
///
/// This is implemented only for the single type `Xstr` (ie, for `str`, or `Path`).
///
/// The bound `str: AsRef<self>`
/// declares that we can cheaply borrow a normal string as an `Xstr`.
///
/// The bound `PathBuf: `[`PathBufExt`]
/// declares that
/// `Pathbuf.`[`try_into_xstring()`](PathBufExt::try_into_xstring) is available -
/// ie, that you can try to obtain an `XString` from a `PathBuf`,
/// which is relevant for home directories and tilde substitution.
///
/// These bounds (and therefore this trait), including the supertrait,
/// are not needed for the code to compile,
/// since we don't have significant amounts of generic code.
/// But they serve as compiler-checked documentation.
pub
/// Methods on `AsRef<`[`Xstr`]`>`
///
/// These methods are used by the implementation in `funcs`
/// to convert the input into the working form,
/// or, to be able to return it unmodified.
///
/// This is implemented (only) for `S: AsRef<Xstr>`.
pub
/// Extension trait on `PathBuf`
///
/// Implemented separately by the code for
/// strings (returning `Option<String>`)
/// and paths (returning `Option<PathBuf>`)
pub
/// Methods (and bounds) on `Wstr`
///
/// `funcs` may also use inherent methods, including slicing,
/// provided they are implemented for both `str` and `RawOsString`,
/// with suitable semantics.
///
/// The bound declares that `&str` or `&RawOsStr` implements `WstrRefExt`
/// so that [`.chars_approx()`](WstrRefExt::chars_approx) is available.
pub
/// Method on the reference [`&Wstr`](Wstr)
///
/// This can't be in the main [`WstrExt`] trait because
/// the type `Chars` would have a lifetime -
/// ie it would be a GAT, which is very new in Rust and we don't want to rely on.
pub
/// Methods on the characters iterator from [`Wstr.chars_approx()`](WstrRefExt::chars_approx)
pub
/// Methods on [`OString`]
///
/// `funcs` may also use inherent methods,
/// provided they are implemented for both `String` and `RawOsString`,
/// with suitable semantics.
pub