Trait rustix::path::Arg
pub trait Arg {
fn as_str(&Self) -> io::Result<&str>;
fn to_string_lossy(&Self) -> Cow<'_, str>;
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>;
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b;
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>;
fn as_cow_c_str(&Self) -> io::Result<Cow<'_, ZStr>> { ... }
fn into_c_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b + Sized,
{ ... }
fn into_with_c_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>,
{ ... }
}
Documentation
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
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
Returns a view of this string as a maybe-owned ZStr
.
fn as_str(&Self) -> io::Result<&str>
Returns a view of this string as a string slice.
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
Runs a closure with self
passed in as a &ZStr
.
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
where
Self: 'b
Consumes self
and returns a view of this string as a maybe-owned
ZStr
.
fn to_string_lossy(&Self) -> Cow<'_, str>
Returns a potentially-lossy rendering of this string as a Cow<'_, str>
.
Provided Methods
fn as_cow_c_str(&Self) -> io::Result<Cow<'_, ZStr>>
Returns a view of this string as a maybe-owned ZStr
.
fn into_c_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b + Sized
where
Self: 'b + Sized
Consumes self
and returns a view of this string as a maybe-owned
ZStr
.
fn into_with_c_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
Runs a closure with self
passed in as a &ZStr
.
Implementations on Foreign Types
impl Arg for &OsStr
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &OsString
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &Path
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &PathBuf
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &String
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &Vec<u8>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &ZStr
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &ZString
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &[u8]
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for &str
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Component<'a>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Components<'a>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Cow<'a, OsStr>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Cow<'a, ZStr>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Cow<'a, str>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl<'a> Arg for Iter<'a>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for OsString
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for PathBuf
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for String
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for Vec<u8>
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>
impl Arg for ZString
fn as_str(&Self) -> io::Result<&str>
fn to_string_lossy(&Self) -> Cow<'_, str>
fn as_cow_z_str(&Self) -> io::Result<Cow<'_, ZStr>>
fn into_z_str<'b>(Self) -> io::Result<Cow<'b, ZStr>>
where
Self: 'b
fn into_with_z_str<T, F>(Self, f: F) -> io::Result<T>
where
Self: Sized,
F: FnOnce(&ZStr) -> io::Result<T>