Skip to main content

FromIo

Trait FromIo 

Source
pub trait FromIo<T> {
    // Required method
    fn map_err_context(self, context: impl FnOnce() -> String) -> T;
}
Expand description

Enables the conversion from std::io::Error to UError and from std::io::Result to UResult.

Required Methods§

Source

fn map_err_context(self, context: impl FnOnce() -> String) -> T

Map the error context of an std::io::Error or std::io::Result to a custom error

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FromIo<Box<UIoError>> for Error

Source§

fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError>

Source§

impl FromIo<Box<UIoError>> for ErrorKind

Source§

fn map_err_context(self, context: impl FnOnce() -> String) -> Box<UIoError>

Source§

impl<T> FromIo<Result<T, Box<dyn UError>>> for Error

Available on Unix only.
Source§

fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T>

Source§

impl<T> FromIo<Result<T, Box<dyn UError>>> for Result<T, Error>

Available on Unix only.

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());
Source§

fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T>

Source§

impl<T> FromIo<Result<T, Box<dyn UError>>> for Result<T>

Source§

fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T>

Implementors§