[−][src]Struct spirit::validation::Action
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::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 failure::ensure; use spirit::prelude::*; use spirit::validation::Action; Spirit::<Empty, Empty>::new() .config_validator(|_old_cfg, new_cfg, _opts| { ensure!(looks_good(new_cfg), "Configuration is broken"); Ok(Action::new()) });
Methods
impl Action
[src]
pub fn new() -> Self
[src]
Creates actions wit both hooks empty.
pub fn on_success<F: FnOnce() + 'static>(self, f: F) -> Self
[src]
Attaches (replaces) the success action.
pub fn on_abort<F: FnOnce() + 'static>(self, f: F) -> Self
[src]
Attaches (replaces) the failure action.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> IntoResult for T
[src]
fn into_result(Self) -> Result<T, Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,