|
| 1 | +use crate::FollowSymlinks; |
| 2 | + |
| 3 | +/// Extension trait for `cap_primitives::fs::OpenOptions` which adds |
| 4 | +/// `sync`, `dsync`, `rsync`, and `nonblock` functions for controlling various |
| 5 | +/// I/O modes for the opened file. |
| 6 | +pub trait OpenOptionsSyncExt { |
| 7 | + /// Requests write operations complete as defined by synchronized I/O file |
| 8 | + /// integrity completion. |
| 9 | + fn sync(&mut self, enable: bool) -> &mut Self; |
| 10 | + |
| 11 | + /// Requests write operations complete as defined by synchronized I/O data |
| 12 | + /// integrity completion. |
| 13 | + fn dsync(&mut self, enable: bool) -> &mut Self; |
| 14 | + |
| 15 | + /// Requests read operations complete as defined by the level of integrity |
| 16 | + /// specified by `sync` and `dsync`. |
| 17 | + fn rsync(&mut self, enable: bool) -> &mut Self; |
| 18 | + |
| 19 | + /// Requests that I/O operations fail with `std::io::ErrorKind::WouldBlock` |
| 20 | + /// if they would otherwise block. |
| 21 | + /// |
| 22 | + /// This option is commonly not implemented for regular files, so blocking |
| 23 | + /// may still occur. |
| 24 | + fn nonblock(&mut self, enable: bool) -> &mut Self; |
| 25 | +} |
| 26 | + |
| 27 | +impl OpenOptionsFollowExt for cap_primitives::fs::OpenOptions { |
| 28 | + #[inline] |
| 29 | + fn sync(&mut self, enable: bool) -> &mut Self { |
| 30 | + // `sync` functionality is implemented within `cap_primitives`; |
| 31 | + // we're just exposing it here since `OpenOptions` is re-exported by |
| 32 | + // `cap_std` etc. and `sync` isn't in `std`. |
| 33 | + self._cap_fs_ext_sync(enable) |
| 34 | + } |
| 35 | + |
| 36 | + #[inline] |
| 37 | + fn dsync(&mut self, enable: bool) -> &mut Self { |
| 38 | + // `dsync` functionality is implemented within `cap_primitives`; |
| 39 | + // we're just exposing it here since `OpenOptions` is re-exported by |
| 40 | + // `cap_std` etc. and `dsync` isn't in `std`. |
| 41 | + self._cap_fs_ext_dsync(enable) |
| 42 | + } |
| 43 | + |
| 44 | + #[inline] |
| 45 | + fn rsync(&mut self, enable: bool) -> &mut Self { |
| 46 | + // `rsync` functionality is implemented within `cap_primitives`; |
| 47 | + // we're just exposing it here since `OpenOptions` is re-exported by |
| 48 | + // `cap_std` etc. and `rsync` isn't in `std`. |
| 49 | + self._cap_fs_ext_rsync(enable) |
| 50 | + } |
| 51 | + |
| 52 | + #[inline] |
| 53 | + fn nonblock(&mut self, enable: bool) -> &mut Self { |
| 54 | + // `nonblock` functionality is implemented within `cap_primitives`; |
| 55 | + // we're just exposing it here since `OpenOptions` is re-exported by |
| 56 | + // `cap_std` etc. and `nonblock` isn't in `std`. |
| 57 | + self._cap_fs_ext_nonblock(enable) |
| 58 | + } |
| 59 | +} |
0 commit comments