Struct spirit::validation::Action [−][src]
pub struct Action { /* fields omitted */ }
Expand description
A validation action.
The validator (see config_validator
) is
supposed to either return an error or an action to be taken once validation completes.
By default, the Action
is empty, but an on_success
and
on_abort
callbacks can be attached to it. These’ll execute once the
validation completes (only one of them will be called, depending on the result of validation).
Examples
use spirit::{Empty, Spirit};
use spirit::prelude::*;
use spirit::validation::Action;
Spirit::<Empty, Empty>::new()
.config_validator(|_old_cfg, new_cfg, _opts| {
let something = create_something(new_cfg)?;
Ok(Action::new().on_success(move || install_something(something)))
});
Or, if you want to only check the configuration:
use spirit::{Empty, Spirit};
use spirit::prelude::*;
use spirit::validation::Action;
Spirit::<Empty, Empty>::new()
.config_validator(|_old_cfg, new_cfg, _opts| {
looks_good(new_cfg)?;
Ok(Action::new())
});