mzcv 0.3.0

Handle controlled vocanulaires (CVs) and ontologies, both statically and dynamically
Documentation
//! The [`CVError`] which makes it easy for downstream users of the error type to match on the exact
//! error.

use context_error::ErrorKind;

/// An error encountered while parsing a CV
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum CVError {
    /// The binary cache does not exist
    CacheDoesNotExist,
    /// The binary cache could not be opened
    CacheCouldNotBeOpenend,
    /// The binary cache could not be made
    CacheCouldNotBeMade,
    /// The binary cache could not be parsed (likely the result of different versions of the same CV
    /// with different struct definitions)
    CacheCouldNotBeParsed,
    /// The CV file does not exist
    #[default]
    FileDoesNotExist,
    /// The CV file could not be made
    FileCouldNotBeMade,
    /// The CV file could not be opened
    FileCouldNotBeOpenend,
    /// The CV file could not be moved
    FileCouldNotBeMoved,
    /// The CV file could not be parsed
    FileCouldNotBeParsed,
    /// The CV does not have a URL set and neither was a URL supplied
    CVUrlNotSet,
    /// The CV could not be read from the given URL, the URL could be wrong, or not up, or fail to
    /// download the file
    CVUrlCouldNotBeRead,
    /// Not enough readers were given for this CV
    MissingReader,
    /// An error encountered while parsing a single item of the CV
    ItemError,
    /// An warning encountered while parsing a single item of the CV
    ItemWarning,
}

impl ErrorKind for CVError {
    type Settings = ();

    fn descriptor(&self) -> &'static str {
        if *self == Self::ItemWarning {
            "warning"
        } else {
            "error"
        }
    }

    fn ignored(&self, _settings: Self::Settings) -> bool {
        false
    }

    fn is_error(&self, _settings: Self::Settings) -> bool {
        *self != Self::ItemWarning
    }
}