Trait posish::path::Arg[][src]

pub trait Arg {
    fn as_str(&self) -> Result<&str>;
fn to_string_lossy(&self) -> Cow<'_, str>;
fn as_c_str(&self) -> Result<Cow<'_, CStr>>;
fn into_c_str<'b>(self) -> Result<Cow<'b, CStr>>
    where
        Self: 'b
;
fn as_maybe_utf8_bytes(&self) -> &[u8];
fn into_with_c_str<T, F>(self, f: F) -> Result<T>
    where
        Self: Sized,
        F: FnOnce(&CStr) -> 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 posish::{io, path::Arg};
use std::ffi::CStr;

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

Return a view of this string as a string slice.

Return a potentially-lossy rendering of this string as a Cow<str>.

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

Consume self and return a view of this string as a maybe-owned CStr.

Return a view of this string as a byte slice.

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

Implementations on Foreign Types

Implementors