devela::_dep::rustix::path

Trait Arg

pub trait Arg {
    // Required methods
    fn as_str(&self) -> Result<&str, Errno> ;
    fn to_string_lossy(&self) -> Cow<'_, str>;
    fn as_cow_c_str(&self) -> Result<Cow<'_, CStr>, Errno> ;
    fn into_c_str<'b>(self) -> Result<Cow<'b, CStr>, Errno> 
       where Self: 'b;
    fn into_with_c_str<T, F>(self, f: F) -> Result<T, Errno> 
       where Self: Sized,
             F: FnOnce(&CStr) -> Result<T, Errno>;
}
Available on crate feature dep_rustix only.
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.

§Examples

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

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

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) -> Result<&str, Errno>

Returns a view of this string as a string slice.

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

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

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

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

fn into_c_str<'b>(self) -> Result<Cow<'b, CStr>, Errno>
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, f: F) -> Result<T, Errno>
where Self: Sized, F: FnOnce(&CStr) -> Result<T, Errno>,

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

Implementations on Foreign Types§

§

impl Arg for &str

§

fn as_str(&self) -> Result<&str, Errno>

§

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

§

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

§

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

§

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

§

impl Arg for &[u8]

§

fn as_str(&self) -> Result<&str, Errno>

§

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

§

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

§

fn into_c_str<'b>(self) -> Result<Cow<'b, CStr>, Errno>
where &[u8]: 'b,

§

fn into_with_c_str<T, F>(self, f: F) -> Result<T, Errno>
where &[u8]: Sized, F: FnOnce(&CStr) -> Result<T, Errno>,

Implementors§

§

impl Arg for &Path

§

impl Arg for &PathBuf

§

impl Arg for &String

§

impl Arg for &Vec<u8>

§

impl Arg for &CStr

§

impl Arg for &CString

§

impl Arg for &OsStr

§

impl Arg for &OsString

§

impl Arg for PathBuf

§

impl Arg for String

§

impl Arg for Vec<u8>

§

impl Arg for CString

§

impl Arg for OsString

§

impl Arg for DecInt

§

impl<'a> Arg for Cow<'a, str>

§

impl<'a> Arg for Cow<'a, CStr>

§

impl<'a> Arg for Cow<'a, OsStr>

§

impl<'a> Arg for Component<'a>

§

impl<'a> Arg for Iter<'a>

§

impl<'a> Arg for Components<'a>