1/// Unix-specific extensions to wrappers in `fs_err` for `std::fs` types.
2pub mod fs {
3 use std::io;
4 use std::path::Path;
5
6 use crate::SourceDestError;
7 use crate::SourceDestErrorKind;
8
9 /// Wrapper for [`std::os::unix::fs::symlink`](https://doc.rust-lang.org/std/os/unix/fs/fn.symlink.html)
10 pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
11 let src = src.as_ref();
12 let dst = dst.as_ref();
13 std::os::unix::fs::symlink(src, dst)
14 .map_err(|err| SourceDestError::build(err, SourceDestErrorKind::Symlink, src, dst))
15 }
16
17 /// Wrapper for [`std::os::unix::fs::FileExt`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html).
18 ///
19 /// The std traits might be extended in the future (See issue [#49961](https://github.com/rust-lang/rust/issues/49961#issuecomment-382751777)).
20 /// This trait is sealed and can not be implemented by other crates.
21 pub trait FileExt: crate::Sealed {
22 /// Wrapper for [`FileExt::read_at`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#tymethod.read_at)
23 fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
24 /// Wrapper for [`FileExt::write_at`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#tymethod.write_at)
25 fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
26 }
27
28 /// Wrapper for [`std::os::unix::fs::OpenOptionsExt`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html)
29 ///
30 /// The std traits might be extended in the future (See issue [#49961](https://github.com/rust-lang/rust/issues/49961#issuecomment-382751777)).
31 /// This trait is sealed and can not be implemented by other crates.
32 pub trait OpenOptionsExt: crate::Sealed {
33 /// Wrapper for [`OpenOptionsExt::mode`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.mode)
34 fn mode(&mut self, mode: u32) -> &mut Self;
35 /// Wrapper for [`OpenOptionsExt::custom_flags`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.custom_flags)
36 fn custom_flags(&mut self, flags: i32) -> &mut Self;
37 }
38}
39