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
// This file was automatically generated by `elaborate`.
// https://github.com/trailofbits/elaborate

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


#[cfg(unix)]
pub trait FileExtContext: std :: os :: unix :: fs :: FileExt {
/// Attempts to write an entire buffer starting from a given offset.
/// 
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
/// 
/// The current file cursor is not affected by this function.
/// 
/// This method will continuously call [`write_at`] until there is no more data
/// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is
/// returned. This method will not return until the entire buffer has been
/// successfully written or such an error occurs. The first error that is
/// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be
/// returned.
/// 
/// # Errors
/// 
/// This function will return the first error of
/// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns.
/// 
/// [`write_at`]: FileExt::write_at
/// 
/// # Examples
/// 
/// ```no_run
/// use std::fs::File;
/// use std::io;
/// use std::os::unix::prelude::FileExt;
/// 
/// fn main() -> io::Result<()> {
///     let file = File::open("foo.txt")?;
/// 
///     // We now write at the offset 10.
///     file.write_all_at(b"sushi", 10)?;
///     Ok(())
/// }
/// ```
fn write_all_at_wc ( & self , buf : & [ u8 ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: write_all_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "write_all_at", buf, offset))
}
/// Like `read_at`, except that it reads into a slice of buffers.
/// 
/// Data is copied to fill each buffer in order, with the final buffer
/// written to possibly being only partially filled. This method must behave
/// equivalently to a single call to read with concatenated buffers.
#[cfg(feature = "unix_file_vectored_at")]
fn read_vectored_at_wc ( & self , bufs : & mut [ std :: io :: IoSliceMut < '_ > ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < usize > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: read_vectored_at(self, bufs, offset)
        .with_context(|| crate::call_failed!(Some(self), "read_vectored_at", bufs, offset))
}
/// Like `write_at`, except that it writes from a slice of buffers.
/// 
/// Data is copied from each buffer in order, with the final buffer read
/// from possibly being only partially consumed. This method must behave as
/// a call to `write_at` with the buffers concatenated would.
#[cfg(feature = "unix_file_vectored_at")]
fn write_vectored_at_wc ( & self , bufs : & [ std :: io :: IoSlice < '_ > ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < usize > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: write_vectored_at(self, bufs, offset)
        .with_context(|| crate::call_failed!(Some(self), "write_vectored_at", bufs, offset))
}
/// Reads a number of bytes starting from a given offset.
/// 
/// Returns the number of bytes read.
/// 
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
/// 
/// The current file cursor is not affected by this function.
/// 
/// Note that similar to [`File::read`], it is not an error to return with a
/// short read.
/// 
/// [`File::read`]: fs::File::read
/// 
/// # Examples
/// 
/// ```no_run
/// use std::io;
/// use std::fs::File;
/// use std::os::unix::prelude::FileExt;
/// 
/// fn main() -> io::Result<()> {
///     let mut buf = [0u8; 8];
///     let file = File::open("foo.txt")?;
/// 
///     // We now read 8 bytes from the offset 10.
///     let num_bytes_read = file.read_at(&mut buf, 10)?;
///     println!("read {num_bytes_read} bytes: {buf:?}");
///     Ok(())
/// }
/// ```
fn read_at_wc ( & self , buf : & mut [ u8 ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < usize > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: read_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "read_at", buf, offset))
}
/// Reads some bytes starting from a given offset into the buffer.
/// 
/// This equivalent to the [`read_at`](FileExt::read_at) method, except that it is passed a
/// [`BorrowedCursor`] rather than `&mut [u8]` to allow use with uninitialized buffers. The new
/// data will be appended to any existing contents of `buf`.
/// 
/// # Examples
/// 
/// ```no_run
/// #![feature(core_io_borrowed_buf)]
/// #![feature(read_buf_at)]
/// 
/// use std::io;
/// use std::io::BorrowedBuf;
/// use std::fs::File;
/// use std::mem::MaybeUninit;
/// use std::os::unix::prelude::*;
/// 
/// fn main() -> io::Result<()> {
///     let mut file = File::open("pi.txt")?;
/// 
///     // Read some bytes starting from offset 2
///     let mut buf: [MaybeUninit<u8>; 10] = [MaybeUninit::uninit(); 10];
///     let mut buf = BorrowedBuf::from(buf.as_mut_slice());
///     file.read_buf_at(buf.unfilled(), 2)?;
/// 
///     assert!(buf.filled().starts_with(b"1"));
/// 
///     Ok(())
/// }
/// ```
#[cfg(feature = "read_buf_at")]
fn read_buf_at_wc ( & self , buf : core :: io :: BorrowedCursor < '_ > , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: read_buf_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "read_buf_at", crate::CustomDebugMessage("value of type BorrowedCursor"), offset))
}
/// Reads the exact number of bytes required to fill `buf` from the given offset.
/// 
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
/// 
/// The current file cursor is not affected by this function.
/// 
/// Similar to [`io::Read::read_exact`] but uses [`read_at`] instead of `read`.
/// 
/// [`read_at`]: FileExt::read_at
/// 
/// # Errors
/// 
/// If this function encounters an error of the kind
/// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation
/// will continue.
/// 
/// If this function encounters an "end of file" before completely filling
/// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`].
/// The contents of `buf` are unspecified in this case.
/// 
/// If any other read error is encountered then this function immediately
/// returns. The contents of `buf` are unspecified in this case.
/// 
/// If this function returns an error, it is unspecified how many bytes it
/// has read, but it will never read more than would be necessary to
/// completely fill the buffer.
/// 
/// # Examples
/// 
/// ```no_run
/// use std::io;
/// use std::fs::File;
/// use std::os::unix::prelude::FileExt;
/// 
/// fn main() -> io::Result<()> {
///     let mut buf = [0u8; 8];
///     let file = File::open("foo.txt")?;
/// 
///     // We now read exactly 8 bytes from the offset 10.
///     file.read_exact_at(&mut buf, 10)?;
///     println!("read {} bytes: {:?}", buf.len(), buf);
///     Ok(())
/// }
/// ```
fn read_exact_at_wc ( & self , buf : & mut [ u8 ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: read_exact_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "read_exact_at", buf, offset))
}
/// Reads the exact number of bytes required to fill the buffer from a given offset.
/// 
/// This is equivalent to the [`read_exact_at`](FileExt::read_exact_at) method, except that it
/// is passed a [`BorrowedCursor`] rather than `&mut [u8]` to allow use with uninitialized
/// buffers. The new data will be appended to any existing contents of `buf`.
/// 
/// # Examples
/// 
/// ```no_run
/// #![feature(core_io_borrowed_buf)]
/// #![feature(read_buf_at)]
/// 
/// use std::io;
/// use std::io::BorrowedBuf;
/// use std::fs::File;
/// use std::mem::MaybeUninit;
/// use std::os::unix::prelude::*;
/// 
/// fn main() -> io::Result<()> {
///     let mut file = File::open("pi.txt")?;
/// 
///     // Read exactly 10 bytes starting from offset 2
///     let mut buf: [MaybeUninit<u8>; 10] = [MaybeUninit::uninit(); 10];
///     let mut buf = BorrowedBuf::from(buf.as_mut_slice());
///     file.read_buf_exact_at(buf.unfilled(), 2)?;
/// 
///     assert_eq!(buf.filled(), b"1415926535");
/// 
///     Ok(())
/// }
/// ```
#[cfg(feature = "read_buf_at")]
fn read_buf_exact_at_wc ( & self , buf : core :: io :: BorrowedCursor < '_ > , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: read_buf_exact_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "read_buf_exact_at", crate::CustomDebugMessage("value of type BorrowedCursor"), offset))
}
/// Writes a number of bytes starting from a given offset.
/// 
/// Returns the number of bytes written.
/// 
/// The offset is relative to the start of the file and thus independent
/// from the current cursor.
/// 
/// The current file cursor is not affected by this function.
/// 
/// When writing beyond the end of the file, the file is appropriately
/// extended and the intermediate bytes are initialized with the value 0.
/// 
/// Note that similar to [`File::write`], it is not an error to return a
/// short write.
/// 
/// # Bug
/// On some systems, `write_at` utilises [`pwrite64`] to write to files.
/// However, this syscall has a [bug] where files opened with the `O_APPEND`
/// flag fail to respect the offset parameter, always appending to the end
/// of the file instead.
/// 
/// It is possible to inadvertently set this flag, like in the example below.
/// Therefore, it is important to be vigilant while changing options to mitigate
/// unexpected behavior.
/// 
/// ```no_run
/// use std::fs::File;
/// use std::io;
/// use std::os::unix::prelude::FileExt;
/// 
/// fn main() -> io::Result<()> {
///     // Open a file with the append option (sets the `O_APPEND` flag)
///     let file = File::options().append(true).open("foo.txt")?;
/// 
///     // We attempt to write at offset 10; instead appended to EOF
///     file.write_at(b"sushi", 10)?;
/// 
///     // foo.txt is 5 bytes long instead of 15
///     Ok(())
/// }
/// ```
/// 
/// [`File::write`]: fs::File::write
/// [`pwrite64`]: https://man7.org/linux/man-pages/man2/pwrite.2.html
/// [bug]: https://man7.org/linux/man-pages/man2/pwrite.2.html#BUGS
/// 
/// # Examples
/// 
/// ```no_run
/// use std::fs::File;
/// use std::io;
/// use std::os::unix::prelude::FileExt;
/// 
/// fn main() -> io::Result<()> {
///     let file = File::create("foo.txt")?;
/// 
///     // We now write at the offset 10.
///     file.write_at(b"sushi", 10)?;
///     Ok(())
/// }
/// ```
fn write_at_wc ( & self , buf : & [ u8 ] , offset : u64 ) -> crate :: rewrite_output_type ! ( std :: io :: Result < usize > ) {
    < Self as :: std :: os :: unix :: fs :: FileExt > :: write_at(self, buf, offset)
        .with_context(|| crate::call_failed!(Some(self), "write_at", buf, offset))
}
}

#[cfg(unix)]
impl<T> FileExtContext for T where T: std :: os :: unix :: fs :: FileExt {}



/// Change the owner and group of the file referenced by the specified open file descriptor.
/// 
/// For semantics and required privileges, see [`chown`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::os::unix::fs;
/// 
/// fn main() -> std::io::Result<()> {
///     let f = std::fs::File::open("/file")?;
///     fs::fchown(&f, Some(0), Some(0))?;
///     Ok(())
/// }
/// ```
#[cfg(unix)]
pub fn fchown_wc < F : std :: os :: fd :: AsFd > ( fd : F , uid : core :: option :: Option < u32 > , gid : core :: option :: Option < u32 > ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let fd = fd.as_fd();
    std :: os :: unix :: fs :: fchown(fd, uid, gid)
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::fchown", fd, uid, gid))
}
/// Change the owner and group of the specified path, without dereferencing symbolic links.
/// 
/// Identical to [`chown`], except that if called on a symbolic link, this will change the owner
/// and group of the link itself rather than the owner and group of the link target.
/// 
/// # Examples
/// 
/// ```no_run
/// use std::os::unix::fs;
/// 
/// fn main() -> std::io::Result<()> {
///     fs::lchown("/symlink", Some(0), Some(0))?;
///     Ok(())
/// }
/// ```
#[cfg(unix)]
pub fn lchown_wc < P : core :: convert :: AsRef < std :: path :: Path > > ( dir : P , uid : core :: option :: Option < u32 > , gid : core :: option :: Option < u32 > ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let dir = dir.as_ref();
    std :: os :: unix :: fs :: lchown(dir, uid, gid)
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::lchown", dir, uid, gid))
}
/// Change the owner and group of the specified path.
/// 
/// Specifying either the uid or gid as `None` will leave it unchanged.
/// 
/// Changing the owner typically requires privileges, such as root or a specific capability.
/// Changing the group typically requires either being the owner and a member of the group, or
/// having privileges.
/// 
/// Be aware that changing owner clears the `suid` and `sgid` permission bits in most cases
/// according to POSIX, usually even if the user is root. The sgid is not cleared when
/// the file is non-group-executable. See: <https://www.man7.org/linux/man-pages/man2/chown.2.html>
/// This call may also clear file capabilities, if there was any.
/// 
/// If called on a symbolic link, this will change the owner and group of the link target. To
/// change the owner and group of the link itself, see [`lchown`].
/// 
/// # Examples
/// 
/// ```no_run
/// use std::os::unix::fs;
/// 
/// fn main() -> std::io::Result<()> {
///     fs::chown("/sandbox", Some(0), Some(0))?;
///     Ok(())
/// }
/// ```
#[cfg(unix)]
pub fn chown_wc < P : core :: convert :: AsRef < std :: path :: Path > > ( dir : P , uid : core :: option :: Option < u32 > , gid : core :: option :: Option < u32 > ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let dir = dir.as_ref();
    std :: os :: unix :: fs :: chown(dir, uid, gid)
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::chown", dir, uid, gid))
}
/// Change the root directory of the current process to the specified path.
/// 
/// This typically requires privileges, such as root or a specific capability.
/// 
/// This does not change the current working directory; you should call
/// [`std::env::set_current_dir`][`crate::env::set_current_dir`] afterwards.
/// 
/// # Examples
/// 
/// ```no_run
/// use std::os::unix::fs;
/// 
/// fn main() -> std::io::Result<()> {
///     fs::chroot("/sandbox")?;
///     std::env::set_current_dir("/")?;
///     // continue working in sandbox
///     Ok(())
/// }
/// ```
#[cfg(unix)]
pub fn chroot_wc < P : core :: convert :: AsRef < std :: path :: Path > > ( dir : P ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let dir = dir.as_ref();
    std :: os :: unix :: fs :: chroot(dir)
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::chroot", dir))
}
/// Create a FIFO special file at the specified path with the specified mode.
/// 
/// # Examples
/// 
/// ```no_run
/// # #![feature(unix_mkfifo)]
/// # #[cfg(not(unix))]
/// # fn main() {}
/// # #[cfg(unix)]
/// # fn main() -> std::io::Result<()> {
/// # use std::{
/// #     os::unix::fs::{mkfifo, PermissionsExt},
/// #     fs::{File, Permissions, remove_file},
/// #     io::{Write, Read},
/// # };
/// # let _ = remove_file("/tmp/fifo");
/// mkfifo("/tmp/fifo", Permissions::from_mode(0o774))?;
/// 
/// let mut wx = File::options().read(true).write(true).open("/tmp/fifo")?;
/// let mut rx = File::open("/tmp/fifo")?;
/// 
/// wx.write_all(b"hello, world!")?;
/// drop(wx);
/// 
/// let mut s = String::new();
/// rx.read_to_string(&mut s)?;
/// 
/// assert_eq!(s, "hello, world!");
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "unix_mkfifo")]
#[cfg(unix)]
pub fn mkfifo_wc < P : core :: convert :: AsRef < std :: path :: Path > > ( path : P , permissions : std :: fs :: Permissions ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let path = path.as_ref();
    std :: os :: unix :: fs :: mkfifo(path, permissions.clone())
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::mkfifo", path, permissions))
}
/// Creates a new symbolic link on the filesystem.
/// 
/// The `link` path will be a symbolic link pointing to the `original` path.
/// 
/// # Examples
/// 
/// ```no_run
/// use std::os::unix::fs;
/// 
/// fn main() -> std::io::Result<()> {
///     fs::symlink("a.txt", "b.txt")?;
///     Ok(())
/// }
/// ```
#[cfg(unix)]
pub fn symlink_wc < P : core :: convert :: AsRef < std :: path :: Path > , Q : core :: convert :: AsRef < std :: path :: Path > > ( original : P , link : Q ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    let original = original.as_ref();
    let link = link.as_ref();
    std :: os :: unix :: fs :: symlink(original, link)
        .with_context(|| crate::call_failed!(None::<()>, "std::os::unix::fs::symlink", original, link))
}