Skip to main content

AsOutput

Trait AsOutput 

Source
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§

Source

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

Turns the reference into the trait object.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

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

Source§

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

Implementors§

Source§

impl AsOutput for &(dyn Output + 'static)