pub trait Definer: __ {
    // Required methods
    fn insert(&mut self, name: &str) -> bool;
    fn out(&mut self) -> &mut dyn Write;

    // Provided method
    fn define_once(
        &mut self,
        name: &str,
        write_typedef: &mut dyn FnMut(&mut dyn Definer) -> Result<()>
    ) -> Result<()> { ... }
}
Available on crate feature headers only.
Expand description

Helper for the generation of C headers.

Defining C headers requires two abstractions:

  • set-like lookup by name, to ensure each type is defined at most once;

  • a Writeable “out stream”, where the headers should be written to.

This trait minimally combines both abstractions, and in exchange offers an auto-implemented non-overridable Definer::define_once().

Required Methods§

source

fn insert(&mut self, name: &str) -> bool

Must return true iff an actual insert happened.

source

fn out(&mut self) -> &mut dyn Write

Yields a handle to the underlying Writer

Provided Methods§

source

fn define_once( &mut self, name: &str, write_typedef: &mut dyn FnMut(&mut dyn Definer) -> Result<()> ) -> Result<()>

Convenience method to perform an .insert() so that if it succeeds (thus guaranteeing the call happens for the first time), it calls write_typedef on itself.

This method cannot be overriden.

Implementors§