Trait obnth::AsPath[][src]

pub trait AsPath {
    fn as_path(&self) -> &Path;

    fn with_cstr<T, F: FnMut(&CStr) -> Result<T>>(&self, mut f: F) -> Result<T> { ... }
}

Represents a string that can be cheaply re-cast as a Path, and possibly also as a CStr.

The design of this was inspired by openat's AsPath trait and nix's NixPath trait. It's essentially a combination of AsRef<Path> and NixPath, which allows it to avoid unnecessary memory allocation in multiple cases.

Required methods

fn as_path(&self) -> &Path[src]

Convert this string to a Path.

This serves a similar purpose to AsRef<Path>::as_ref(), so many of the AsRef rules apply (i.e. it should be very inexpensive and never fail).

Loading content...

Provided methods

fn with_cstr<T, F: FnMut(&CStr) -> Result<T>>(&self, mut f: F) -> Result<T>[src]

Calls the given closure with a version of self converted to a CStr.

The CStr may actually be a CString (allocated from the heap), or it may be the original string if that string is already nul-terminated.

IMPORTANT: If the string contains an interior nul byte that prevents it from being converted to a CString, the closure will not be called, and a std::io::Error converted from a std::ffi::NulError will be returned.

Loading content...

Implementations on Foreign Types

impl AsPath for &Path[src]

impl AsPath for PathBuf[src]

impl AsPath for &PathBuf[src]

impl AsPath for &str[src]

impl AsPath for String[src]

impl AsPath for &String[src]

impl AsPath for &OsStr[src]

impl AsPath for OsString[src]

impl AsPath for &OsString[src]

impl AsPath for &CStr[src]

impl AsPath for CString[src]

impl AsPath for &CString[src]

Loading content...

Implementors

Loading content...