elaborate 1.0.0

Wrappers for standard library functions and types to produce more elaborate error messages
Documentation
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
// This file was automatically generated by `elaborate`.
// https://github.com/trailofbits/elaborate

#[allow(unused_imports)]
use anyhow::Context;



pub trait PathBufContext {
/// Invokes [`try_reserve_exact`] on the underlying instance of [`OsString`].
/// 
/// [`try_reserve_exact`]: OsString::try_reserve_exact
fn try_reserve_exact_wc ( & mut self , additional : usize ) -> crate :: rewrite_output_type ! ( core :: result :: Result < ( ) , std :: collections :: TryReserveError > );
/// Invokes [`try_reserve`] on the underlying instance of [`OsString`].
/// 
/// [`try_reserve`]: OsString::try_reserve
fn try_reserve_wc ( & mut self , additional : usize ) -> crate :: rewrite_output_type ! ( core :: result :: Result < ( ) , std :: collections :: TryReserveError > );
}
impl PathBufContext for std :: path :: PathBuf {
fn try_reserve_exact_wc ( & mut self , additional : usize ) -> crate :: rewrite_output_type ! ( core :: result :: Result < ( ) , std :: collections :: TryReserveError > ) {
    std :: path :: PathBuf :: try_reserve_exact(self, additional)
        .with_context(|| crate::call_failed!(Some(self), "try_reserve_exact", additional))
}
fn try_reserve_wc ( & mut self , additional : usize ) -> crate :: rewrite_output_type ! ( core :: result :: Result < ( ) , std :: collections :: TryReserveError > ) {
    std :: path :: PathBuf :: try_reserve(self, additional)
        .with_context(|| crate::call_failed!(Some(self), "try_reserve", additional))
}
}
pub trait PathContext {
/// Extracts the extension (without the leading dot) of [`self.file_name`], if possible.
/// 
/// The extension is:
/// 
/// * [`None`], if there is no file name;
/// * [`None`], if there is no embedded `.`;
/// * [`None`], if the file name begins with `.` and has no other `.`s within;
/// * Otherwise, the portion of the file name after the final `.`
/// 
/// [`self.file_name`]: Path::file_name
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// 
/// assert_eq!("rs", Path::new("foo.rs").extension().unwrap());
/// assert_eq!("gz", Path::new("foo.tar.gz").extension().unwrap());
/// ```
fn extension_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > );
/// Extracts the prefix of [`self.file_name`].
/// 
/// The prefix is:
/// 
/// * [`None`], if there is no file name;
/// * The entire file name if there is no embedded `.`;
/// * The portion of the file name before the first non-beginning `.`;
/// * The entire file name if the file name begins with `.` and has no other `.`s within;
/// * The portion of the file name before the second `.` if the file name begins with `.`
/// 
/// [`self.file_name`]: Path::file_name
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// 
/// assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap());
/// assert_eq!("foo", Path::new("foo.tar.gz").file_prefix().unwrap());
/// assert_eq!(".config", Path::new(".config").file_prefix().unwrap());
/// assert_eq!(".config", Path::new(".config.toml").file_prefix().unwrap());
/// ```
/// 
/// # See Also
/// This method is similar to [`Path::file_stem`], which extracts the portion of the file name
/// before the *last* `.`
/// 
/// [`Path::file_stem`]: Path::file_stem
#[cfg(feature = "path_file_prefix")]
fn file_prefix_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > );
/// Extracts the stem (non-extension) portion of [`self.file_name`].
/// 
/// [`self.file_name`]: Path::file_name
/// 
/// The stem is:
/// 
/// * [`None`], if there is no file name;
/// * The entire file name if there is no embedded `.`;
/// * The entire file name if the file name begins with `.` and has no other `.`s within;
/// * Otherwise, the portion of the file name before the final `.`
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// 
/// assert_eq!("foo", Path::new("foo.rs").file_stem().unwrap());
/// assert_eq!("foo.tar", Path::new("foo.tar.gz").file_stem().unwrap());
/// ```
/// 
/// # See Also
/// This method is similar to [`Path::file_prefix`], which extracts the portion of the file name
/// before the *first* `.`
/// 
/// [`Path::file_prefix`]: Path::file_prefix
fn file_stem_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > );
/// Normalize a path, including `..` without traversing the filesystem.
/// 
/// Returns an error if normalization would leave leading `..` components.
/// 
/// <div class="warning">
/// 
/// This function always resolves `..` to the "lexical" parent.
/// That is "a/b/../c" will always resolve to `a/c` which can change the meaning of the path.
/// In particular, `a/c` and `a/b/../c` are distinct on many systems because `b` may be a symbolic link, so its parent isn't `a`.
/// 
/// </div>
/// 
/// [`path::absolute`](absolute) is an alternative that preserves `..`.
/// Or [`Path::canonicalize`] can be used to resolve any `..` by querying the filesystem.
#[cfg(feature = "normalize_lexically")]
fn normalize_lexically_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: result :: Result < std :: path :: PathBuf , std :: path :: NormalizeError > );
/// Queries the file system to get information about a file, directory, etc.
/// 
/// This function will traverse symbolic links to query information about the
/// destination file.
/// 
/// This is an alias to [`fs::metadata`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::Path;
/// 
/// let path = Path::new("/Minas/tirith");
/// let metadata = path.metadata().expect("metadata call failed");
/// println!("{:?}", metadata.file_type());
/// ```
fn metadata_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: Metadata > );
/// Queries the metadata about a file without following symlinks.
/// 
/// This is an alias to [`fs::symlink_metadata`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::Path;
/// 
/// let path = Path::new("/Minas/tirith");
/// let metadata = path.symlink_metadata().expect("symlink_metadata call failed");
/// println!("{:?}", metadata.file_type());
/// ```
fn symlink_metadata_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: Metadata > );
/// Reads a symbolic link, returning the file that the link points to.
/// 
/// This is an alias to [`fs::read_link`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::Path;
/// 
/// let path = Path::new("/laputa/sky_castle.rs");
/// let path_link = path.read_link().expect("read_link call failed");
/// ```
fn read_link_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: path :: PathBuf > );
/// Returns `Ok(true)` if the path points at an existing entity.
/// 
/// This function will traverse symbolic links to query information about the
/// destination file. In case of broken symbolic links this will return `Ok(false)`.
/// 
/// [`Path::exists()`] only checks whether or not a path was both found and readable. By
/// contrast, `try_exists` will return `Ok(true)` or `Ok(false)`, respectively, if the path
/// was _verified_ to exist or not exist. If its existence can neither be confirmed nor
/// denied, it will propagate an `Err(_)` instead. This can be the case if e.g. listing
/// permission is denied on one of the parent directories.
/// 
/// Note that while this avoids some pitfalls of the `exists()` method, it still can not
/// prevent time-of-check to time-of-use ([TOCTOU]) bugs. You should only use it in scenarios
/// where those bugs are not an issue.
/// 
/// This is an alias for [`std::fs::exists`](crate::fs::exists).
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::Path;
/// assert!(!Path::new("does_not_exist.txt").try_exists().expect("Can't check existence of file does_not_exist.txt"));
/// assert!(Path::new("/root/secret_file.txt").try_exists().is_err());
/// ```
/// 
/// [TOCTOU]: fs#time-of-check-to-time-of-use-toctou
/// [`exists()`]: Self::exists
fn try_exists_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < bool > );
/// Returns a path that, when joined onto `base`, yields `self`.
/// 
/// # Errors
/// 
/// If `base` is not a prefix of `self` (i.e., [`starts_with`]
/// returns `false`), returns [`Err`].
/// 
/// [`starts_with`]: Path::starts_with
/// 
/// # Examples
/// 
/// ```
/// use std::path::{Path, PathBuf};
/// 
/// let path = Path::new("/test/haha/foo.txt");
/// 
/// assert_eq!(path.strip_prefix("/"), Ok(Path::new("test/haha/foo.txt")));
/// assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt")));
/// assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt")));
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new("")));
/// assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new("")));
/// 
/// assert!(path.strip_prefix("test").is_err());
/// assert!(path.strip_prefix("/te").is_err());
/// assert!(path.strip_prefix("/haha").is_err());
/// 
/// let prefix = PathBuf::from("/test/");
/// assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt")));
/// ```
fn strip_prefix_wc < P > ( & self , base : P ) -> crate :: rewrite_output_type ! ( core :: result :: Result < & Self , std :: path :: StripPrefixError > ) where P : core :: convert :: AsRef < std :: path :: Path >;
/// Returns an iterator over the entries within a directory.
/// 
/// The iterator will yield instances of <code>[io::Result]<[fs::DirEntry]></code>. New
/// errors may be encountered after an iterator is initially constructed.
/// 
/// This is an alias to [`fs::read_dir`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::Path;
/// 
/// let path = Path::new("/laputa");
/// for entry in path.read_dir().expect("read_dir call failed") {
///     if let Ok(entry) = entry {
///         println!("{:?}", entry.path());
///     }
/// }
/// ```
fn read_dir_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: ReadDir > );
/// Returns the `Path` without its final component, if there is one.
/// 
/// This means it returns `Some("")` for relative paths with one component.
/// 
/// Returns [`None`] if the path terminates in a root or prefix, or if it's
/// the empty string.
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// 
/// let path = Path::new("/foo/bar");
/// let parent = path.parent().unwrap();
/// assert_eq!(parent, Path::new("/foo"));
/// 
/// let grand_parent = parent.parent().unwrap();
/// assert_eq!(grand_parent, Path::new("/"));
/// assert_eq!(grand_parent.parent(), None);
/// 
/// let relative_path = Path::new("foo/bar");
/// let parent = relative_path.parent();
/// assert_eq!(parent, Some(Path::new("foo")));
/// let grand_parent = parent.and_then(Path::parent);
/// assert_eq!(grand_parent, Some(Path::new("")));
/// let great_grand_parent = grand_parent.and_then(Path::parent);
/// assert_eq!(great_grand_parent, None);
/// ```
fn parent_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & Self > );
/// Returns the canonical, absolute form of the path with all intermediate
/// components normalized and symbolic links resolved.
/// 
/// This is an alias to [`fs::canonicalize`].
/// 
/// # Errors
/// 
/// This method will return an error in the following situations, but is not
/// limited to just these cases:
/// 
/// * `path` does not exist.
/// * A non-final component in path is not a directory.
/// 
/// # Examples
/// 
/// ```no_run
/// use std::path::{Path, PathBuf};
/// 
/// let path = Path::new("/foo/test/../test/bar.rs");
/// assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs"));
/// ```
fn canonicalize_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: path :: PathBuf > );
/// Returns the final component of the `Path`, if there is one.
/// 
/// If the path is a normal file, this is the file name. If it's the path of a directory, this
/// is the directory name.
/// 
/// Returns [`None`] if the path terminates in `..`.
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// use std::ffi::OsStr;
/// 
/// assert_eq!(Some(OsStr::new("bin")), Path::new("/usr/bin/").file_name());
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("tmp/foo.txt").file_name());
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
/// assert_eq!(None, Path::new("/").file_name());
/// ```
fn file_name_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > );
/// Yields a [`&str`] slice if the `Path` is valid unicode.
/// 
/// This conversion may entail doing a check for UTF-8 validity.
/// Note that validation is performed because non-UTF-8 strings are
/// perfectly valid for some OS.
/// 
/// [`&str`]: str
/// 
/// # Examples
/// 
/// ```
/// use std::path::Path;
/// 
/// let path = Path::new("foo.txt");
/// assert_eq!(path.to_str(), Some("foo.txt"));
/// ```
fn to_str_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & str > );
}
impl PathContext for std :: path :: Path {
fn extension_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > ) {
    std :: path :: Path :: extension(self)
        .with_context(|| crate::call_failed!(Some(self), "extension"))
}
#[cfg(feature = "path_file_prefix")]
fn file_prefix_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > ) {
    std :: path :: Path :: file_prefix(self)
        .with_context(|| crate::call_failed!(Some(self), "file_prefix"))
}
fn file_stem_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > ) {
    std :: path :: Path :: file_stem(self)
        .with_context(|| crate::call_failed!(Some(self), "file_stem"))
}
#[cfg(feature = "normalize_lexically")]
fn normalize_lexically_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: result :: Result < std :: path :: PathBuf , std :: path :: NormalizeError > ) {
    std :: path :: Path :: normalize_lexically(self)
        .with_context(|| crate::call_failed!(Some(self), "normalize_lexically"))
}
fn metadata_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: Metadata > ) {
    std :: path :: Path :: metadata(self)
        .with_context(|| crate::call_failed!(Some(self), "metadata"))
}
fn symlink_metadata_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: Metadata > ) {
    std :: path :: Path :: symlink_metadata(self)
        .with_context(|| crate::call_failed!(Some(self), "symlink_metadata"))
}
fn read_link_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: path :: PathBuf > ) {
    std :: path :: Path :: read_link(self)
        .with_context(|| crate::call_failed!(Some(self), "read_link"))
}
fn try_exists_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < bool > ) {
    std :: path :: Path :: try_exists(self)
        .with_context(|| crate::call_failed!(Some(self), "try_exists"))
}
fn strip_prefix_wc < P > ( & self , base : P ) -> crate :: rewrite_output_type ! ( core :: result :: Result < & Self , std :: path :: StripPrefixError > ) where P : core :: convert :: AsRef < std :: path :: Path > {
    let base = base.as_ref();
    std :: path :: Path :: strip_prefix(self, base)
        .with_context(|| crate::call_failed!(Some(self), "strip_prefix", base))
}
fn read_dir_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: fs :: ReadDir > ) {
    std :: path :: Path :: read_dir(self)
        .with_context(|| crate::call_failed!(Some(self), "read_dir"))
}
fn parent_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & Self > ) {
    std :: path :: Path :: parent(self)
        .with_context(|| crate::call_failed!(Some(self), "parent"))
}
fn canonicalize_wc ( & self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: path :: PathBuf > ) {
    std :: path :: Path :: canonicalize(self)
        .with_context(|| crate::call_failed!(Some(self), "canonicalize"))
}
fn file_name_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & std :: ffi :: OsStr > ) {
    std :: path :: Path :: file_name(self)
        .with_context(|| crate::call_failed!(Some(self), "file_name"))
}
fn to_str_wc ( & self ) -> crate :: rewrite_output_type ! ( core :: option :: Option < & str > ) {
    std :: path :: Path :: to_str(self)
        .with_context(|| crate::call_failed!(Some(self), "to_str"))
}
}


/// Makes the path absolute without accessing the filesystem.
/// 
/// If the path is relative, the current directory is used as the base directory.
/// All intermediate components will be resolved according to platform-specific
/// rules, but unlike [`canonicalize`][crate::fs::canonicalize], this does not
/// resolve symlinks and may succeed even if the path does not exist.
/// 
/// If the `path` is empty or getting the
/// [current directory][crate::env::current_dir] fails, then an error will be
/// returned.
/// 
/// # Platform-specific behavior
/// 
/// On POSIX platforms, the path is resolved using [POSIX semantics][posix-semantics],
/// except that it stops short of resolving symlinks. This means it will keep `..`
/// components and trailing separators.
/// 
/// On Windows, for verbatim paths, this will simply return the path as given. For other
/// paths, this is currently equivalent to calling
/// [`GetFullPathNameW`][windows-path].
/// 
/// On Cygwin, this is currently equivalent to calling [`cygwin_conv_path`][cygwin-path]
/// with mode `CCP_WIN_A_TO_POSIX`, and then being processed like other POSIX platforms.
/// If a Windows path is given, it will be converted to an absolute POSIX path without
/// keeping `..`.
/// 
/// Note that these [may change in the future][changes].
/// 
/// # Errors
/// 
/// This function may return an error in the following situations:
/// 
/// * If `path` is syntactically invalid; in particular, if it is empty.
/// * If getting the [current directory][crate::env::current_dir] fails.
/// 
/// # Examples
/// 
/// ## POSIX paths
/// 
/// ```
/// # #[cfg(unix)]
/// fn main() -> std::io::Result<()> {
///     use std::path::{self, Path};
/// 
///     // Relative to absolute
///     let absolute = path::absolute("foo/./bar")?;
///     assert!(absolute.ends_with("foo/bar"));
/// 
///     // Absolute to absolute
///     let absolute = path::absolute("/foo//test/.././bar.rs")?;
///     assert_eq!(absolute, Path::new("/foo/test/../bar.rs"));
///     Ok(())
/// }
/// # #[cfg(not(unix))]
/// # fn main() {}
/// ```
/// 
/// ## Windows paths
/// 
/// ```
/// # #[cfg(windows)]
/// fn main() -> std::io::Result<()> {
///     use std::path::{self, Path};
/// 
///     // Relative to absolute
///     let absolute = path::absolute("foo/./bar")?;
///     assert!(absolute.ends_with(r"foo\bar"));
/// 
///     // Absolute to absolute
///     let absolute = path::absolute(r"C:\foo//test\..\./bar.rs")?;
/// 
///     assert_eq!(absolute, Path::new(r"C:\foo\bar.rs"));
///     Ok(())
/// }
/// # #[cfg(not(windows))]
/// # fn main() {}
/// ```
/// 
/// Note that this [may change in the future][changes].
/// 
/// [changes]: io#platform-specific-behavior
/// [posix-semantics]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
/// [windows-path]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew
/// [cygwin-path]: https://cygwin.com/cygwin-api/func-cygwin-conv-path.html
pub fn absolute_wc < P : core :: convert :: AsRef < std :: path :: Path > > ( path : P ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: path :: PathBuf > ) {
    let path = path.as_ref();
    std :: path :: absolute(path)
        .with_context(|| crate::call_failed!(None::<()>, "std::path::absolute", path))
}