From bdd8126b938de11272f79bb7f512316740469ed7 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 27 Jan 2023 14:22:33 +0000 Subject: use cap-std --- openat/src/name.rs | 76 ------------------------------------------------------ 1 file changed, 76 deletions(-) delete mode 100644 openat/src/name.rs (limited to 'openat/src/name.rs') diff --git a/openat/src/name.rs b/openat/src/name.rs deleted file mode 100644 index c181db1..0000000 --- a/openat/src/name.rs +++ /dev/null @@ -1,76 +0,0 @@ -use std::ffi::{OsStr, CStr, CString}; -use std::path::{Path, PathBuf}; -use std::os::unix::ffi::OsStrExt; - -use crate::{Entry}; - - -/// The purpose of this is similar to `AsRef` but it's optimized for -/// things that can be directly used as `CStr` (which is type passed to -/// the underlying system call). -/// -/// This trait should be implemented for everything for which `AsRef` -/// is implemented -pub trait AsPath { - /// The return value of the `to_path` that holds data copied from the - /// original path (if copy is needed, otherwise it's just a reference) - type Buffer: AsRef; - /// Returns `None` when path contains a zero byte - fn to_path(self) -> Option; -} - -impl<'a> AsPath for &'a Path { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self.as_os_str().as_bytes()).ok() - } -} - -impl<'a> AsPath for &'a PathBuf { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self.as_os_str().as_bytes()).ok() - } -} - -impl<'a> AsPath for &'a OsStr { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self.as_bytes()).ok() - } -} - -impl<'a> AsPath for &'a str { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self.as_bytes()).ok() - } -} - -impl<'a> AsPath for &'a String { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self.as_bytes()).ok() - } -} - -impl<'a> AsPath for String { - type Buffer = CString; - fn to_path(self) -> Option { - CString::new(self).ok() - } -} - -impl<'a> AsPath for &'a CStr { - type Buffer = &'a CStr; - fn to_path(self) -> Option<&'a CStr> { - Some(self) - } -} - -impl<'a> AsPath for &'a Entry { - type Buffer = &'a CStr; - fn to_path(self) -> Option<&'a CStr> { - Some(&self.name) - } -} -- cgit v1.2.3-54-g00ecf