Trait io_extra::IoErrorExt

source ·
pub trait IoErrorExt: Sealed {
Show 21 methods // Provided methods fn addr_in_use(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn addr_not_available( error: impl Into<Box<dyn Error + Send + Sync>> ) -> Error { ... } fn already_exists(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn broken_pipe(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn connection_aborted( error: impl Into<Box<dyn Error + Send + Sync>> ) -> Error { ... } fn connection_refused( error: impl Into<Box<dyn Error + Send + Sync>> ) -> Error { ... } fn connection_reset(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn interrupted(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn invalid_data(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn invalid_input(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn not_connected(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn not_found(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn out_of_memory(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn permission_denied( error: impl Into<Box<dyn Error + Send + Sync>> ) -> Error { ... } fn timed_out(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn unexpected_eof(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn unsupported(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn would_block(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn write_zero(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error { ... } fn context(self, msg: impl Display) -> Error { ... } fn io_context(self, msg: impl Display) -> Error { ... }
}
Expand description

An extension trait for io::Error, with shorthand constructors for various io::ErrorKinds.

use std::io;
use io_extra::IoErrorExt as _;

fn read_to_string(mut r: impl io::Read) -> io::Result<String> {
    let mut buf = vec![];
    r.read_to_end(&mut buf)?;
    String::from_utf8(buf).map_err(io::Error::invalid_data)
}

fn check_magic_number(mut r: impl io::Read) -> io::Result<()> {
    let mut buf = [0; 2];
    r.read_exact(&mut buf)?;
    match buf == 0xDEAD_u16.to_le_bytes() {
        true => Ok(()),
        false => Err(io::Error::invalid_data("unrecognised format"))
    }
}

This trait is sealed, and cannot be implemented by types outside this library.

Provided Methods§

source

fn addr_in_use(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind AddrInUse, wrapping the passed in error.

source

fn addr_not_available(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind AddrNotAvailable, wrapping the passed in error.

source

fn already_exists(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind AlreadyExists, wrapping the passed in error.

source

fn broken_pipe(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind BrokenPipe, wrapping the passed in error.

source

fn connection_aborted(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind ConnectionAborted, wrapping the passed in error.

source

fn connection_refused(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind ConnectionRefused, wrapping the passed in error.

source

fn connection_reset(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind ConnectionReset, wrapping the passed in error.

source

fn interrupted(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind Interrupted, wrapping the passed in error.

source

fn invalid_data(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind InvalidData, wrapping the passed in error.

source

fn invalid_input(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind InvalidInput, wrapping the passed in error.

source

fn not_connected(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind NotConnected, wrapping the passed in error.

source

fn not_found(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind NotFound, wrapping the passed in error.

source

fn out_of_memory(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind OutOfMemory, wrapping the passed in error.

source

fn permission_denied(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind PermissionDenied, wrapping the passed in error.

source

fn timed_out(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind TimedOut, wrapping the passed in error.

source

fn unexpected_eof(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind UnexpectedEof, wrapping the passed in error.

source

fn unsupported(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind Unsupported, wrapping the passed in error.

source

fn would_block(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind WouldBlock, wrapping the passed in error.

source

fn write_zero(error: impl Into<Box<dyn Error + Send + Sync>>) -> Error

Create an io::Error with kind WriteZero, wrapping the passed in error.

source

fn context(self, msg: impl Display) -> Error

Attach a message to this error.

source

fn io_context(self, msg: impl Display) -> Error

Attach a message to this error.

Provided with a different name to not conflict with anyhow::Context.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl IoErrorExt for Error

Implementors§