lazippy 0.0.1

Pure-Rust LZMA (Lempel-Ziv-Markov chain Algorithm), part of the 8z umbrella
Documentation
use std::fmt;
use std::io;
use thiserror::Error;

/// All errors produced by lazippy.
#[derive(Error, Debug)]
pub enum LazippyError {
    /// Returned by every stub until the real implementation lands.
    #[error("not yet implemented")]
    NotYetImplemented,

    /// Wraps an underlying IO error.
    #[error("IO error: {0}")]
    Io(#[from] io::Error),

    /// Error from the lzma-rust2 backend (Phase 1).
    #[error("LZMA backend error: {0}")]
    Backend(String),

    /// The LZMA stream header was malformed.
    #[error("invalid header: {0}")]
    InvalidHeader(String),

    /// The LZMA properties byte (lc/lp/pb encoding) was out of range.
    #[error("invalid properties byte: {0:#04x}")]
    InvalidProperties(u8),

    /// The input was truncated before the stream end marker.
    #[error("truncated LZMA stream")]
    Truncated,

    /// An error in the range-coder state machine.
    #[error("range coder error: {0}")]
    RangeCoder(String),
}

impl LazippyError {
    /// Construct an [`InvalidHeader`](LazippyError::InvalidHeader) error from any `Display` value.
    pub fn invalid_header<T: fmt::Display>(msg: T) -> Self {
        LazippyError::InvalidHeader(msg.to_string())
    }

    /// Construct a [`RangeCoder`](LazippyError::RangeCoder) error from any `Display` value.
    pub fn range_coder<T: fmt::Display>(msg: T) -> Self {
        LazippyError::RangeCoder(msg.to_string())
    }
}

/// Convenience alias used throughout lazippy.
pub type LazippyResult<T> = Result<T, LazippyError>;