pub trait Arg {
    fn as_str(&self) -> Result<&str>;
fn to_string_lossy(&self) -> Cow<'_, str>;
fn as_cow_z_str(&self) -> Result<Cow<'_, ZStr>>;
fn into_z_str<'b>(self) -> Result<Cow<'b, ZStr>>
    where
        Self: 'b
;
fn into_with_z_str<T, F>(self, f: F) -> Result<T>
    where
        Self: Sized,
        F: FnOnce(&ZStr) -> Result<T>
; fn as_cow_c_str(&self) -> Result<Cow<'_, ZStr>> { ... }
fn into_c_str<'b>(self) -> Result<Cow<'b, ZStr>>
    where
        Self: 'b + Sized
, { ... }
fn into_with_c_str<T, F>(self, f: F) -> Result<T>
    where
        Self: Sized,
        F: FnOnce(&ZStr) -> Result<T>
, { ... } }
Expand description

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.

Example

use rustix::ffi::ZStr;
use rustix::io;
use rustix::path::Arg;

pub fn touch<P: Arg>(path: P) -> io::Result<()> {
    let path = path.into_z_str()?;
    _touch(&path)
}

fn _touch(path: &ZStr) -> io::Result<()> {
    // implementation goes here
    Ok(())
}

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

Required methods

Returns a view of this string as a string slice.

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

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

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

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

Provided methods

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

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

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

Implementations on Foreign Types

Implementors