Trait Arg

trait Arg

A trait for passing path arguments.

This is similar to AsRef<Path>, but is implemented for more kinds of strings and can convert into more kinds of strings.

Examples

# #[cfg(any(feature = "fs", feature = "net"))]
use rustix::ffi::CStr;
use rustix::io;
# #[cfg(any(feature = "fs", feature = "net"))]
use rustix::path::Arg;

# #[cfg(any(feature = "fs", feature = "net"))]
pub fn touch<P: Arg>(path: P) -> io::Result<()> {
    let path = path.into_c_str()?;
    _touch(&path)
}

# #[cfg(any(feature = "fs", feature = "net"))]
fn _touch(path: &CStr) -> io::Result<()> {
    // implementation goes here
    Ok(())
}

Users can then call touch("foo"), touch(cstr!("foo")), touch(Path::new("foo")), or many other things.

Required Methods

fn as_str(self: &Self) -> Result<&str>

Returns a view of this string as a string slice.

fn to_string_lossy(self: &Self) -> Cow<'_, str>

Returns a potentially-lossy rendering of this string as a Cow<'_, str>.

fn as_cow_c_str(self: &Self) -> Result<Cow<'_, CStr>>

Returns a view of this string as a maybe-owned CStr.

fn into_c_str<'b>(self: Self) -> Result<Cow<'b, CStr>>
where
    Self: 'b

Consumes self and returns a view of this string as a maybe-owned CStr.

fn into_with_c_str<T, F>(self: Self, f: F) -> Result<T>
where
    Self: Sized,
    F: FnOnce(&CStr) -> Result<T>

Runs a closure with self passed in as a &CStr.

Implementors