Trait Generator

Source
pub trait Generator: Default {
    type Options: Default + Debug;

    // Required method
    fn generate_with_options<W>(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        options: Self::Options,
        path: Option<PathBuf>,
        writer: &mut W,
    ) -> Result<(), Error>
       where W: Write + Sized;

    // Provided methods
    fn generate<W>(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        path: Option<PathBuf>,
        writer: &mut W,
    ) -> Result<(), Error>
       where W: Write + Sized { ... }
    fn generate_to_string(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        options: Self::Options,
        path: Option<PathBuf>,
    ) -> Result<String, Error> { ... }
    fn generate_to_file(
        &mut self,
        module: &Module,
        cache: &impl ModuleStore,
        options: Self::Options,
        path: &PathBuf,
    ) -> Result<(), Error> { ... }
}
Expand description

This trait denotes a type that generates content from a module.

The type Options denotes some type that contains any settings that affect the behavior of the generator. If no settings are required Options may be set to (). Given that options are provided at the method level it is recommended that generators are constructed using Default::default().

Required Associated Types§

Required Methods§

Source

fn generate_with_options<W>( &mut self, module: &Module, cache: &impl ModuleStore, options: Self::Options, path: Option<PathBuf>, writer: &mut W, ) -> Result<(), Error>
where W: Write + Sized,

Generate from the given module into the provided writer.

Provided Methods§

Source

fn generate<W>( &mut self, module: &Module, cache: &impl ModuleStore, path: Option<PathBuf>, writer: &mut W, ) -> Result<(), Error>
where W: Write + Sized,

Generate from the given module into the provided writer. Note that this calls generate_with_options using Self::Options::default().

Source

fn generate_to_string( &mut self, module: &Module, cache: &impl ModuleStore, options: Self::Options, path: Option<PathBuf>, ) -> Result<String, Error>

Generate from the given module into a string.

Source

fn generate_to_file( &mut self, module: &Module, cache: &impl ModuleStore, options: Self::Options, path: &PathBuf, ) -> Result<(), Error>

Generate from the given module into a file.

Note: The referenced file will be created if it does not exist, and replaced if it does.

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.

Implementors§