InputErrorKind#

The category of an InputError: input that couldn't be decoded, or input that decoded but broke a validation rule. Read it from InputError::kind after matching Error::Input.

Declaration#

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum InputErrorKind {
    Parse,
    Validation,
}

With the serde feature, InputErrorKind implements Serialize and Deserialize as "parse" and "validation".

Variants#

Variant When it occurs
Parse JSON input couldn't be decoded. Only the separate plen-wire decoding crate produces it; no call in plen-core returns it. The error's path is None.
Validation The data or options passed to a call break a validation rule. Every Error::Input returned by a plen-core call has this kind, as does a converted MatchError::Invalid. InputError::validation builds an error of this kind.

Example#

use plen_core::{schedule, Error, InputErrorKind, ProjectData, SolveOptions, TaskData};

fn main() {
    // A task with no start, end or duration fails strict validation.
    let data = ProjectData {
        tasks: vec![TaskData::new(1)],
        ..Default::default()
    };

    match schedule(data, &SolveOptions::default()) {
        Err(Error::Input(e)) if e.kind == InputErrorKind::Validation => {
            println!("invalid input at {:?}: {}", e.path, e.message);
        }
        Err(e) => println!("other error: {e}"),
        Ok(result) => println!("{} updates", result.updates.len()),
    }
}