Expand description
The basic helper trait.
It allows being plugged into a builder and modifying it in an arbitrary way.
It is more common to apply the helper by the
Builder::with
method than directly.
There’s an implementation of Helper
for FnOnce(Builder) -> Builder
, so helpers can be
either custom types or just closures (which are often more convenient than defining an empty
type and the implementation).
use spirit::{Builder, Empty, Spirit};
use spirit::helpers::Helper;
struct CfgPrint;
impl Helper<Empty, Empty> for CfgPrint {
fn apply(self, builder: Builder<Empty, Empty>) -> Builder<Empty, Empty> {
builder.on_config(|_opts, _config| println!("Config changed"))
}
}
Spirit::<Empty, Empty>::new()
.with(CfgPrint)
.run(|_spirit| {
println!("Running...");
Ok(())
})
use spirit::{Builder, Empty, Spirit};
fn cfg_print(builder: Builder<Empty, Empty>) -> Builder<Empty, Empty> {
builder.on_config(|_opts, _config| println!("Config changed"))
}
Spirit::<Empty, Empty>::new()
.with(cfg_print)
.run(|_spirit| {
println!("Running...");
Ok(())
})