diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-17 01:03:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 01:03:02 +0000 |
commit | 2f78ec2bba5bbeac2c666745da1423b8c326f61a (patch) | |
tree | 76ac48b3886d70f7a4d99de3a8249f9cc0ab859c /src/lib.rs | |
parent | 2ae94ebdd8a46f8860b9e89253654e20017cd355 (diff) | |
parent | 9d8c8c92adcb74277331a827ca991a04cc4ea36f (diff) | |
download | nix-2f78ec2bba5bbeac2c666745da1423b8c326f61a.zip |
Merge #1242
1242: Don't implement `NixPath` for `Option<&P> where P: NixPath` r=asomers a=asomers
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.
Co-authored-by: Alan Somers <asomers@gmail.com>
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) } - } - } -} |