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 to
| 66 | /// |
| 67 | /// [`AsRef`]: std::convert::AsRef |
| 68 | pub trait Arg { |
| 69 | /// Returns a view of this string as a string slice. |
| 70 | fn as_str(&self) -> io::Result<&str>; |
| 71 | |
| 72 | /// Returns a potentially-lossy rendering of this string as a |
| 73 | /// `Cow<'_, str>`. |
| 74 | #[cfg(feature = "alloc")] |
| 75 | fn to_string_lossy(&self) -> Cow<'_, str>; |
| 76 | |
| 77 | /// Returns a view of this string as a maybe-owned [`CStr`]. |
| 78 | #[cfg(feature = "alloc")] |
| 79 | fn as_cow_c_str(&self) -> io::Result<Cow<'_, CStr>>; |
| 80 | |
| 81 | /// Consumes `self` and returns a view of this string as a maybe-owned |
| 82 | /// [`CStr`]. |
| 83 | #[cfg(feature = "alloc")] |
| 84 | fn into_c_str<'b>(self) -> io::Result<Cow<'b, CStr>> |
| 85 | where |
| 86 | Self: 'b; |
| 87 | |
| 88 | /// Runs a closure with `self` passed in as a `&CStr`. |
| 89 | fn into_with_c_str<T, F>(self, f: F) -> io::Result<T> |
| 90 | where |
| 91 | Self: Sized, |
| 92 | F: FnOnce(&CStr) -> io::Result<T>; |
| 93 | } |
| 94 | |
| 95 | /// Runs a closure on `arg` where `A` is mapped to a `&CStr` |
| 96 | pub fn option_into_with_c_str<T, F, A>(arg: Option<A>, f: F) -> io::Result<T> |
nothing calls this directly
no outgoing calls
no test coverage detected