mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
docs: add usage example for nix::Errno
conversion
This commit is contained in:
parent
990bb4224d
commit
c19c19e4db
1 changed files with 14 additions and 0 deletions
|
@ -508,6 +508,20 @@ impl From<std::io::Error> for Box<dyn UError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enables the conversion from [`Result<T, nix::Error>`] to [`UResult<T>`].
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use uucore::error::FromIo;
|
||||||
|
/// use nix::errno::Errno;
|
||||||
|
///
|
||||||
|
/// let nix_err = Err::<(), nix::Error>(Errno::EACCES);
|
||||||
|
/// let uio_result = nix_err.map_err_context(|| String::from("fix me please!"));
|
||||||
|
///
|
||||||
|
/// // prints "fix me please!: Permission denied"
|
||||||
|
/// println!("{}", uio_result.unwrap_err());
|
||||||
|
/// ```
|
||||||
impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
|
impl<T> FromIo<UResult<T>> for Result<T, nix::Error> {
|
||||||
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
|
||||||
self.map_err(|e| {
|
self.map_err(|e| {
|
||||||
|
|
Loading…
Reference in a new issue