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