Skip to main content

Writer

Struct Writer 

Source
pub struct Writer<A, W> { /* private fields */ }
Expand description

A Writer monad: a computation that produces a log alongside a value.

Wraps a pair (A, W) where W is a monoid.

Implementations§

Source§

impl<A, W: Default + Clone> Writer<A, W>

Source

pub fn new(value: A, log: W) -> Self

Create a writer with the given value and log.

Source

pub fn pure(value: A) -> Self

Return a writer that writes nothing.

Source

pub fn get_value(self) -> A

Extract the value.

Source

pub fn get_log(&self) -> &W

Extract the log.

Source

pub fn run(self) -> (A, W)

Run the writer, producing (value, log).

Auto Trait Implementations§

§

impl<A, W> Freeze for Writer<A, W>
where A: Freeze, W: Freeze,

§

impl<A, W> RefUnwindSafe for Writer<A, W>

§

impl<A, W> Send for Writer<A, W>
where A: Send, W: Send,

§

impl<A, W> Sync for Writer<A, W>
where A: Sync, W: Sync,

§

impl<A, W> Unpin for Writer<A, W>
where A: Unpin, W: Unpin,

§

impl<A, W> UnsafeUnpin for Writer<A, W>
where A: UnsafeUnpin, W: UnsafeUnpin,

§

impl<A, W> UnwindSafe for Writer<A, W>
where A: UnwindSafe, W: 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.