Struct eos_rs::api::io::IntoInnerError

source ·
pub struct IntoInnerError<W>(_, _);
Expand description

An error returned by BufWriter::into_inner which combines an error that happened while writing out the buffer, and the buffered writer object which may be used to recover from the condition.

Examples

use acid_io::{BufWriter, Write};

let mut writer = BufWriter::new(Vec::new());

// do stuff with the vec
writer.write_all("I live in a vector now!".as_bytes())?;

// we want to get our `Vec` back, so let's try:

let buf = match writer.into_inner() {
    Ok(b) => b,
    Err(e) => {
        // Here, e is an IntoInnerError
        panic!("An error occurred");
    }
};

Implementations§

source§

impl<W> IntoInnerError<W>

source

pub fn error(&self) -> &Error

Returns the error which caused the call to BufWriter::into_inner() to fail.

This error was returned when attempting to write the internal buffer.

Examples
use acid_io::{BufWriter, Write};

let mut writer = BufWriter::new(Vec::new());

// do stuff with the vec
writer.write_all("I live in a vector now!".as_bytes())?;

// we want to get our `Vec` back, so let's try:

let buf = match writer.into_inner() {
    Ok(b) => b,
    Err(e) => {
        // Here, e is an IntoInnerError
        panic!("An error occurred: {}", e.error());
    }
};
source

pub fn into_inner(self) -> W

Returns the buffered writer instance which generated the error.

The returned object can be used for error recovery, such as re-inspecting the buffer.

Examples
use acid_io::{BufWriter, Write};

let mut writer = BufWriter::new(Vec::new());

// do stuff with the vec
writer.write_all("I live in a vector now!".as_bytes())?;

// we want to get our `Vec` back, so let's try:

let buf = match writer.into_inner() {
    Ok(b) => b,
    Err(e) => {
        // Get the writer back after an error:
        let w: BufWriter<_> = e.into_inner();
        // And unwrap the buffer:
        w.into_inner().unwrap()
    }
};
source

pub fn into_error(self) -> Error

Consumes the IntoInnerError and returns the error which caused the call to BufWriter::into_inner() to fail. Unlike error, this can be used to obtain ownership of the underlying error.

Example
use acid_io::{BufWriter, ErrorKind, Write};

let mut not_enough_space = [0u8; 10];
let mut stream = BufWriter::new(not_enough_space.as_mut());
write!(stream, "this cannot be actually written").unwrap();
let into_inner_err = stream.into_inner().expect_err("now we discover it's too small");
let err = into_inner_err.into_error();
assert_eq!(err.kind(), ErrorKind::WriteZero);
source

pub fn into_parts(self) -> (Error, W)

Consumes the IntoInnerError and returns the error which caused the call to BufWriter::into_inner() to fail, and the underlying writer.

This can be used to simply obtain ownership of the underlying error; it can also be used for advanced error recovery.

Example
use acid_io::{BufWriter, ErrorKind, Write};

let mut not_enough_space = [0u8; 10];
let mut stream = BufWriter::new(not_enough_space.as_mut());
write!(stream, "this cannot be actually written").unwrap();
let into_inner_err = stream.into_inner().expect_err("now we discover it's too small");
let (err, recovered_writer) = into_inner_err.into_parts();
assert_eq!(err.kind(), ErrorKind::WriteZero);
assert_eq!(recovered_writer.buffer(), b"t be actually written");

Trait Implementations§

source§

impl<W> Debug for IntoInnerError<W>where W: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<W> Display for IntoInnerError<W>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<W> From<IntoInnerError<W>> for Error

source§

fn from(iie: IntoInnerError<W>) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<W> !RefUnwindSafe for IntoInnerError<W>

§

impl<W> Send for IntoInnerError<W>where W: Send,

§

impl<W> Sync for IntoInnerError<W>where W: Sync,

§

impl<W> Unpin for IntoInnerError<W>where W: Unpin,

§

impl<W> !UnwindSafe for IntoInnerError<W>

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> ToString for Twhere T: Display + ?Sized,

§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.