Function resolve_plugins

Source
pub fn resolve_plugins<'a>(
    plugins: &'a [Box<dyn KorokPlugin + 'a>],
) -> ResolvePluginsResult<'a>
Expand description

Reduce all plugins into a single function that runs them in sequence.

For instance, imagine we have a list of plugins [A, B, C] implemented as:

use codama_errors::CodamaResult;
use codama_korok_plugins::KorokPlugin;
use codama_korok_visitors::KorokVisitable;

struct LoggingPluging;
impl KorokPlugin for LoggingPluging {
    fn run(&self, visitable: &mut dyn KorokVisitable, next: &dyn Fn(&mut dyn KorokVisitable) -> CodamaResult<()>) -> CodamaResult<()> {
        println!("Plugin X - before");
        next(visitable)?;
        println!("Plugin X - after");
        Ok(())
    }
}

Where X is A, B, or C. The resolve_plugins function will return a function that prints the following:

Plugin C - before
Plugin B - before
Plugin A - before
Plugin A - after
Plugin B - after
Plugin C - after