Trait obnth::AsPath [−][src]
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).
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.