guix-scheme 0.1.0

Read, edit, and generate Guix Scheme files (channels.scm, system config.scm) from Rust
Documentation
use std::fmt;

#[derive(Debug)]
pub enum Error {
    Parse(scheme_edit::ParseError),
    NoChannelsForm,
    ChannelNotFound(String),
    MissingField { record: String, field: String },
    Invalid { field: String, reason: String },
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Parse(e) => write!(f, "parse error: {e}"),
            Error::NoChannelsForm => write!(f, "no `list` / `cons*` / `cons` form found"),
            Error::ChannelNotFound(name) => write!(f, "channel `{name}` not found"),
            Error::MissingField { record, field } => write!(f, "{record}: missing {field}"),
            Error::Invalid { field, reason } => write!(f, "invalid {field}: {reason}"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Parse(e) => Some(e),
            _ => None,
        }
    }
}

impl From<scheme_edit::ParseError> for Error {
    fn from(e: scheme_edit::ParseError) -> Self {
        Error::Parse(e)
    }
}