diff options
author | Alan Somers <asomers@gmail.com> | 2020-05-16 14:36:10 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2020-05-16 14:43:54 -0600 |
commit | 9d8c8c92adcb74277331a827ca991a04cc4ea36f (patch) | |
tree | 4c8699171cc73ddba51e2b56af2c54c4c14460f9 /src/lib.rs | |
parent | 465a8f73134de0eec1bf28c749cc89cece0c7a1a (diff) | |
download | nix-9d8c8c92adcb74277331a827ca991a04cc4ea36f.zip |
Don't implement `NixPath` for `Option<&P> where P: NixPath`
Most Nix functions that accept `NixPath` arguments can't do anything
useful with `None`. The exceptions (`mount` and `quotactl_sync`)
already take explicitly optional arguments.
Also, this changes the behavior of `mount` with `None` arguments.
Previously, it would call mount(2) with empty strings for those
arguments. Now, it will use null pointers.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 19 |
1 files changed, 0 insertions, 19 deletions
@@ -283,22 +283,3 @@ impl NixPath for PathBuf { self.as_os_str().with_nix_path(f) } } - -/// Treats `None` as an empty string. -impl<'a, NP: ?Sized + NixPath> NixPath for Option<&'a NP> { - fn is_empty(&self) -> bool { - self.map_or(true, NixPath::is_empty) - } - - fn len(&self) -> usize { - self.map_or(0, NixPath::len) - } - - fn with_nix_path<T, F>(&self, f: F) -> Result<T> where F: FnOnce(&CStr) -> T { - if let Some(nix_path) = *self { - nix_path.with_nix_path(f) - } else { - unsafe { CStr::from_ptr("\0".as_ptr() as *const _).with_nix_path(f) } - } - } -} |