summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2019-08-19 15:55:25 -0600
committerAlan Somers <asomers@gmail.com>2019-08-29 10:06:02 -0600
commit417e91363a25c663ff884f3dcb879832bf0a66ed (patch)
treee4643f14f1701edc48d0818ef1b4707377f77612 /src/lib.rs
parentfaaacf959a47f286306ae73a2b24a649e2249199 (diff)
downloadnix-417e91363a25c663ff884f3dcb879832bf0a66ed.zip
Clippy cleanup
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 71485d2a..e3f064c6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -121,9 +121,9 @@ impl Error {
/// let e = Error::from(Errno::EPERM);
/// assert_eq!(Some(Errno::EPERM), e.as_errno());
/// ```
- pub fn as_errno(&self) -> Option<Errno> {
- if let &Error::Sys(ref e) = self {
- Some(*e)
+ pub fn as_errno(self) -> Option<Errno> {
+ if let Error::Sys(e) = self {
+ Some(e)
} else {
None
}
@@ -177,6 +177,8 @@ impl fmt::Display for Error {
}
pub trait NixPath {
+ fn is_empty(&self) -> bool;
+
fn len(&self) -> usize;
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
@@ -184,6 +186,10 @@ pub trait NixPath {
}
impl NixPath for str {
+ fn is_empty(&self) -> bool {
+ NixPath::is_empty(OsStr::new(self))
+ }
+
fn len(&self) -> usize {
NixPath::len(OsStr::new(self))
}
@@ -195,6 +201,10 @@ impl NixPath for str {
}
impl NixPath for OsStr {
+ fn is_empty(&self) -> bool {
+ self.as_bytes().is_empty()
+ }
+
fn len(&self) -> usize {
self.as_bytes().len()
}
@@ -206,6 +216,10 @@ impl NixPath for OsStr {
}
impl NixPath for CStr {
+ fn is_empty(&self) -> bool {
+ self.to_bytes().is_empty()
+ }
+
fn len(&self) -> usize {
self.to_bytes().len()
}
@@ -222,6 +236,10 @@ impl NixPath for CStr {
}
impl NixPath for [u8] {
+ fn is_empty(&self) -> bool {
+ self.is_empty()
+ }
+
fn len(&self) -> usize {
self.len()
}
@@ -249,6 +267,10 @@ impl NixPath for [u8] {
}
impl NixPath for Path {
+ fn is_empty(&self) -> bool {
+ NixPath::is_empty(self.as_os_str())
+ }
+
fn len(&self) -> usize {
NixPath::len(self.as_os_str())
}
@@ -259,6 +281,10 @@ impl NixPath for Path {
}
impl NixPath for PathBuf {
+ fn is_empty(&self) -> bool {
+ NixPath::is_empty(self.as_os_str())
+ }
+
fn len(&self) -> usize {
NixPath::len(self.as_os_str())
}
@@ -270,6 +296,10 @@ impl NixPath for PathBuf {
/// 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)
}