Open

Trait Open 

Source
pub trait Open {
    type W: Open<Error = Self::Error>;
    type Error: Display + Debug;

    // Required methods
    fn writer(&mut self) -> &mut Self::W;
    fn write_fmt(&mut self, arg: Arguments<'_>) -> Result<(), Self::Error>;

    // Provided methods
    fn ref_open<O: Opener>(
        &mut self,
        e: O,
    ) -> Result<WriteScope<O::Close, &mut Self::W>, <Self::W as Open>::Error> { ... }
    fn open_scope<O: Opener>(
        &mut self,
        e: O,
        f: impl FnOnce(&mut WriteScope<O::Close, &mut Self::W>) -> Result<(), <Self::W as Open>::Error>,
    ) -> Result<(), <Self::W as Open>::Error> { ... }
    fn open<O: Opener>(
        self,
        e: O,
    ) -> Result<WriteScope<O::Close, Self>, <Self::W as Open>::Error>
       where Self: Sized { ... }
    fn text(&mut self, d: impl Display) -> Result<(), <Self::W as Open>::Error> { ... }
}
Expand description

The work-horse of this crate.

This is a kind of hybrid between DerefMut where Target: Write, and Write itself, with added methods with default implementations to open scopes. This is done in one big traits rather than with super traits to avoid issues with the orphan rule.

Required Associated Types§

Source

type W: Open<Error = Self::Error>

The underlying writer’s type

Source

type Error: Display + Debug

The Error that happens when writing

Required Methods§

Source

fn writer(&mut self) -> &mut Self::W

The underlying writer

Source

fn write_fmt(&mut self, arg: Arguments<'_>) -> Result<(), Self::Error>

Write-like interface allowing to be used with the write! macro

Provided Methods§

Source

fn ref_open<O: Opener>( &mut self, e: O, ) -> Result<WriteScope<O::Close, &mut Self::W>, <Self::W as Open>::Error>

Open a new scope, taking a reference to self

Source

fn open_scope<O: Opener>( &mut self, e: O, f: impl FnOnce(&mut WriteScope<O::Close, &mut Self::W>) -> Result<(), <Self::W as Open>::Error>, ) -> Result<(), <Self::W as Open>::Error>

Open a scope and pass it as argument to the provided closure, closing it at the closures end

Source

fn open<O: Opener>( self, e: O, ) -> Result<WriteScope<O::Close, Self>, <Self::W as Open>::Error>
where Self: Sized,

Open a new scope taking self by ownership

Source

fn text(&mut self, d: impl Display) -> Result<(), <Self::W as Open>::Error>

Write the argument to the writer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Open> Open for &mut T

Source§

type Error = <T as Open>::Error

Source§

type W = T

Source§

fn write_fmt(&mut self, arg: Arguments<'_>) -> Result<(), Self::Error>

Source§

fn writer(&mut self) -> &mut Self::W

Implementors§

Source§

impl<E: Closer, W: Open> Open for WriteScope<E, W>

Source§

type W = W

Source§

type Error = <W as Open>::Error

Source§

impl<W: Write> Open for WrapFmt<W>

Source§

impl<W: Write> Open for WrapIO<W>

Available on crate feature std only.