fs_err/os/
unix.rs

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    /// Creates a new symbolic link on the filesystem.
10    ///
11    /// The `link` path will be a symbolic link pointing to the `original` path.
12    ///
13    /// Wrapper for [`std::os::unix::fs::symlink`](https://doc.rust-lang.org/std/os/unix/fs/fn.symlink.html)
14    pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
15        let original = original.as_ref();
16        let link = link.as_ref();
17        std::os::unix::fs::symlink(original, link).map_err(|err| {
18            SourceDestError::build(err, SourceDestErrorKind::Symlink, link, original)
19        })
20    }
21
22    /// Wrapper for [`std::os::unix::fs::FileExt`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html).
23    ///
24    /// The std traits might be extended in the future (See issue [#49961](https://github.com/rust-lang/rust/issues/49961#issuecomment-382751777)).
25    /// This trait is sealed and can not be implemented by other crates.
26    pub trait FileExt: crate::Sealed {
27        /// Wrapper for [`FileExt::read_at`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#tymethod.read_at)
28        fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize>;
29        /// Wrapper for [`FileExt::write_at`](https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#tymethod.write_at)
30        fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize>;
31    }
32
33    /// Wrapper for [`std::os::unix::fs::OpenOptionsExt`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html)
34    ///
35    /// The std traits might be extended in the future (See issue [#49961](https://github.com/rust-lang/rust/issues/49961#issuecomment-382751777)).
36    /// This trait is sealed and can not be implemented by other crates.
37    pub trait OpenOptionsExt: crate::Sealed {
38        /// Wrapper for [`OpenOptionsExt::mode`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.mode)
39        fn mode(&mut self, mode: u32) -> &mut Self;
40        /// Wrapper for [`OpenOptionsExt::custom_flags`](https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html#tymethod.custom_flags)
41        fn custom_flags(&mut self, flags: i32) -> &mut Self;
42    }
43}