zenops 0.20.0

Declarative system configuration management for shell config and dotfiles.
//! `picker`-scoped error type.
//!
//! Failures from the interactive multi-row picker used by `zenops import`:
//! terminal I/O (raw mode toggle, key reads, screen writes) and the user
//! aborting at the picker prompt. Exposed to the rest of the crate as
//! `crate::Error::Picker` via `#[error(transparent)]` + `#[from]`.

/// Failure modes for [`super::Picker`] implementations and the helpers
/// they use.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// I/O error toggling raw mode / alt-screen, reading a key, or writing
    /// to the terminal during a picker session.
    #[error("Terminal I/O failed during picker: {0}")]
    Io(#[source] std::io::Error),
}

impl PartialEq for Error {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Io(l), Self::Io(r)) => l.kind() == r.kind(),
        }
    }
}

#[cfg(test)]
mod tests {
    use std::io;

    use similar_asserts::assert_eq;

    use super::*;

    fn io(kind: io::ErrorKind) -> io::Error {
        io::Error::from(kind)
    }

    #[test]
    fn io_eq_compares_kind() {
        let a = Error::Io(io(io::ErrorKind::BrokenPipe));
        let b = Error::Io(io(io::ErrorKind::BrokenPipe));
        let c = Error::Io(io(io::ErrorKind::Other));
        assert_eq!(a, b);
        assert_ne!(a, c);
    }
}