InMemoryOutput

Struct InMemoryOutput 

Source
pub struct InMemoryOutput<Ctx, Err = Infallible> { /* private fields */ }
Expand description

An output implementation that just writes to a string.

This output itself produces no errors and the write futures complete instantly. It uses InMemoryIo as the IO type.

However, for compatibility with higher level code that uses a different error type, the error type can be selected by the type parameter Err. Note that Err must be convertible from Infallible. Regardless of the error type chosen, it will never be returned from this output itself.

Implementations§

Source§

impl<Ctx, Err> InMemoryOutput<Ctx, Err>

Source

pub fn new(context: Ctx) -> Self

Source§

impl<Ctx, Err> InMemoryOutput<Ctx, Err>
where Ctx: Context, Err: From<Infallible>,

Source

pub fn try_print_output<W>(context: Ctx, writable: &W) -> Result<String, Err>
where W: Writable<Self>,

Gets the string output of a single writable.

Assumes that the only source of async is this InMemoryOutput itself, i.e. the writable will never return a pending future unless the output used with it returns a pending future. Because of its async-rejecting nature, this function is intended for testing purposes.

Panics if the writable returns a pending future (particularly, this may happen if a writable introduces its own async computations that do not come from the output)

Source§

impl<Ctx> InMemoryOutput<Ctx>
where Ctx: Context,

Source

pub fn print_output<W>(context: Ctx, writable: &W) -> String
where W: Writable<Self>,

Gets the string output of a single writable.

Infallible version of [try_print_output]. See that function’s documentation for full details.

Panics if the writable returns a pending future (particularly, this may happen if a writable introduces its own async computations that do not come from the output)

Trait Implementations§

Source§

impl<Ctx, Err> Output for InMemoryOutput<Ctx, Err>
where Ctx: Context, Err: From<Infallible>,

Source§

type Io<'b> = InMemoryIo<'b> where Self: 'b

The I/O stream type
Source§

type Ctx = Ctx

The context holder
Source§

type Error = Err

The error type for write operations.
Source§

async fn write(&mut self, value: &str) -> Result<(), Self::Error>

Writes the given value to the output.
Source§

fn split(&mut self) -> (Self::Io<'_>, &Self::Ctx)

Splits into the context and the I/O stream, so that they can be used separately
Source§

fn context(&self) -> &Self::Ctx

Gets all the context associated with this output
Source§

fn get_ctx<T>(&self) -> &T
where Self::Ctx: ContextProvides<T>,

Gets a particular context value

Auto Trait Implementations§

§

impl<Ctx, Err> Freeze for InMemoryOutput<Ctx, Err>
where Ctx: Freeze,

§

impl<Ctx, Err> RefUnwindSafe for InMemoryOutput<Ctx, Err>
where Ctx: RefUnwindSafe,

§

impl<Ctx, Err> Send for InMemoryOutput<Ctx, Err>
where Ctx: Send,

§

impl<Ctx, Err> Sync for InMemoryOutput<Ctx, Err>
where Ctx: Sync,

§

impl<Ctx, Err> Unpin for InMemoryOutput<Ctx, Err>
where Ctx: Unpin,

§

impl<Ctx, Err> UnwindSafe for InMemoryOutput<Ctx, Err>
where Ctx: UnwindSafe,

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.