crabka-compression 0.1.2

Kafka wire-protocol compression codecs for Rust
Documentation
//! Errors returned by `compress` and `decompress`.

use thiserror::Error;

/// Errors that can occur during compression or decompression.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CompressionError {
    /// The requested codec was not enabled at compile time. The codec name
    /// is one of `"gzip"`, `"snappy"`, `"lz4"`, `"zstd"`.
    #[error("compression feature `{0}` not enabled at compile time")]
    FeatureDisabled(&'static str),

    /// The compressed payload could not be parsed (truncated input, bad
    /// framing, invalid checksum, etc.).
    #[error("invalid compressed data: {0}")]
    InvalidData(String),

    /// I/O error from one of the codec libraries.
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn feature_disabled_display() {
        let e = CompressionError::FeatureDisabled("snappy");
        assert_eq!(
            e.to_string(),
            "compression feature `snappy` not enabled at compile time"
        );
    }
}