AsOutput

Trait AsOutput 

pub trait AsOutput {
    // Required method
    fn as_output(&self) -> &(dyn Output + 'static);
}
Expand description

A trait for accepting an arbitrary kind of output as an argument.

Can be used to accept a reference to

  • any kind of sized type that implements Output, or
  • the trait object [&dyn Output].

Should be used as impl AsOutput rather than &impl AsOutput.

§Why is this needed?

Unfortunately, &impl Output can’t be turned into &dyn Output in a generic function. Directly accepting &dyn Output is of course also possible, but is less convenient, especially in cases where the document is optional.

See also https://users.rust-lang.org/t/converting-from-generic-unsized-parameter-to-trait-object/72376

Required Methods§

fn as_output(&self) -> &(dyn Output + 'static)

Turns the reference into the trait object.

Implementations on Foreign Types§

§

impl<T> AsOutput for &T
where T: Output,

§

fn as_output(&self) -> &(dyn Output + 'static)

Implementors§

§

impl AsOutput for &(dyn Output + 'static)