compio_buf

Struct BufResult

Source
pub struct BufResult<T, B>(pub Result<T>, pub B);
Expand description

A specialized Result type for operations with buffers.

This type is used as a return value for asynchronous compio methods that require passing ownership of a buffer to the runtime. When the operation completes, the buffer is returned no matter if the operation completed successfully.

Tuple Fields§

§0: Result<T>§1: B

Implementations§

Source§

impl<T, B> BufResult<T, B>

Source

pub const fn is_ok(&self) -> bool

Returns true if the result is Ok.

Source

pub const fn is_err(&self) -> bool

Returns true if the result is Err.

Source

pub fn map<U>(self, f: impl FnOnce(T, B) -> (U, B)) -> BufResult<U, B>

Maps the result part, and allows updating the buffer.

Source

pub fn map2<U, C>( self, f_ok: impl FnOnce(T, B) -> (U, C), f_err: impl FnOnce(B) -> C, ) -> BufResult<U, C>

Maps the result part, and allows changing the buffer type.

Source

pub fn map_res<U>(self, f: impl FnOnce(T) -> U) -> BufResult<U, B>

Maps the result part, and keeps the buffer unchanged.

Source

pub fn map_buffer<C>(self, f: impl FnOnce(B) -> C) -> BufResult<T, C>

Maps the buffer part, and keeps the result unchanged.

Source

pub fn and_then<U>( self, f: impl FnOnce(T, B) -> (Result<U>, B), ) -> BufResult<U, B>

Updating the result type and modifying the buffer.

Source

pub fn expect(self, msg: &str) -> (T, B)

Returns the contained Ok value, consuming the self value.

Source

pub fn unwrap(self) -> (T, B)

Returns the contained Ok value, consuming the self value.

Trait Implementations§

Source§

impl<T, B> From<(Result<T, Error>, B)> for BufResult<T, B>

Source§

fn from((res, buf): (Result<T>, B)) -> Self

Converts to this type from the input type.
Source§

impl<T, B> From<BufResult<T, B>> for (Result<T>, B)

Source§

fn from(BufResult: BufResult<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T, B> FromResidual<BufResult<Infallible, B>> for BufResult<T, B>

Available on crate feature try_trait_v2 only.
fn foo() -> BufResult<i32, i32> {
    let (a, b) = BufResult(Ok(1), 2)?;
    assert_eq!(a, 1);
    assert_eq!(b, 2);
    (Ok(3), 4).into()
}
assert!(foo().is_ok());
Source§

fn from_residual(residual: BufResult<Infallible, B>) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<T, B> FromResidual<BufResult<Infallible, B>> for Result<T>

Available on crate feature try_trait_v2 only.
fn foo() -> std::io::Result<i32> {
    let (a, b) = BufResult(Ok(1), 2)?;
    assert_eq!(a, 1);
    assert_eq!(b, 2);
    Ok(3)
}
assert!(foo().is_ok());
Source§

fn from_residual(residual: BufResult<Infallible, B>) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<T: IntoInner, O> IntoInner for BufResult<O, T>

Source§

type Inner = BufResult<O, <T as IntoInner>::Inner>

The inner type.
Source§

fn into_inner(self) -> Self::Inner

Get the inner buffer.
Source§

impl<T, B> Residual<(T, B)> for BufResult<Infallible, B>

Available on crate feature try_trait_v2 only.
Source§

type TryType = BufResult<T, B>

🔬This is a nightly-only experimental API. (try_trait_v2_residual)
The “return” type of this meta-function.
Source§

impl<T, B> Try for BufResult<T, B>

Available on crate feature try_trait_v2 only.
Source§

type Output = (T, B)

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
Source§

type Residual = BufResult<Infallible, B>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more
Source§

fn from_output((res, buf): Self::Output) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
Source§

fn branch(self) -> ControlFlow<Self::Residual, Self::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more

Auto Trait Implementations§

§

impl<T, B> Freeze for BufResult<T, B>
where B: Freeze, T: Freeze,

§

impl<T, B> !RefUnwindSafe for BufResult<T, B>

§

impl<T, B> Send for BufResult<T, B>
where B: Send, T: Send,

§

impl<T, B> Sync for BufResult<T, B>
where B: Sync, T: Sync,

§

impl<T, B> Unpin for BufResult<T, B>
where B: Unpin, T: Unpin,

§

impl<T, B> !UnwindSafe for BufResult<T, B>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.