docs: add usage example for nix::Errno conversion

This commit is contained in:
Orhun Parmaksız 2022-10-22 21:26:33 +03:00
parent 990bb4224d
commit c19c19e4db
No known key found for this signature in database
GPG key ID: F83424824B3E4B90

View file

@ -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> {
fn map_err_context(self, context: impl FnOnce() -> String) -> UResult<T> {
self.map_err(|e| {