cap_fs_ext/open_options_maybe_dir_ext.rs
1/// Extension trait for `cap_primitives::fs::OpenOptions` which adds
2/// `maybe_dir`, a function for controlling whether an open should attempt to
3/// succeed on a directory. On Posix-ish platforms, opening a directory always
4/// succeeds, but on Windows, opening a directory needs this option.
5pub trait OpenOptionsMaybeDirExt {
6 /// Sets the option for disabling an error that might be generated by the
7 /// opened object being a directory.
8 ///
9 /// On some platforms, this may prevent the directory from being deleted
10 /// or renamed while the handle is open.
11 fn maybe_dir(&mut self, maybe_dir: bool) -> &mut Self;
12}
13
14impl OpenOptionsMaybeDirExt for cap_primitives::fs::OpenOptions {
15 #[inline]
16 fn maybe_dir(&mut self, maybe_dir: bool) -> &mut Self {
17 // `maybe_dir` functionality is implemented within `cap_primitives`;
18 // we're just exposing it here since `OpenOptions` is re-exported by
19 // `cap_std` etc. and `maybe_dir` isn't in `std`.
20 self._cap_fs_ext_maybe_dir(maybe_dir)
21 }
22}