cbor-ld 0.1.0

CBOR-LD 1.0 processor built on cbor2 with semantic compression, JSON-LD context processing, type tables and deterministic CBOR output.
Documentation
use std::fmt;

/// A result type returned by this crate.
pub type Result<T> = std::result::Result<T, Error>;

/// Errors returned by the CBOR-LD processor.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
    /// cbor2 failed to encode, decode, or validate data.
    Cbor(String),
    /// The input is not a CBOR-LD 1.0 tagged value.
    NotCborld(String),
    /// A required registry type table was not provided.
    NoTypeTable(u64),
    /// The type table contains an unsupported literal type.
    UnsupportedLiteralType(String),
    /// A JSON-LD term definition is not valid for CBOR-LD processing.
    InvalidTermDefinition(String),
    /// A protected term was redefined.
    ProtectedTermRedefinition(String),
    /// A remote context was needed but could not be loaded.
    DocumentLoader(String),
    /// A compressed context could not be resolved.
    UndefinedCompressedContext(u64),
    /// A compressed term ID could not be resolved.
    UnknownTermId(u64),
    /// A compressed table value could not be resolved.
    UnknownCompressedValue(u64),
    /// A compressed value uses invalid bytes.
    UnrecognizedBytes(String),
    /// The input shape is invalid for the active CBOR-LD algorithm.
    InvalidInput(String),
    /// A value cannot be encoded by a required codec.
    UnsupportedValue(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Cbor(msg) => write!(f, "CBOR error: {msg}"),
            Self::NotCborld(msg) => write!(f, "not CBOR-LD: {msg}"),
            Self::NoTypeTable(id) => write!(f, "type table not found for registry entry {id}"),
            Self::UnsupportedLiteralType(t) => {
                write!(f, "unsupported literal type in type table: {t}")
            }
            Self::InvalidTermDefinition(msg) => write!(f, "invalid term definition: {msg}"),
            Self::ProtectedTermRedefinition(term) => {
                write!(f, "unexpected redefinition of protected term {term:?}")
            }
            Self::DocumentLoader(msg) => write!(f, "document loader error: {msg}"),
            Self::UndefinedCompressedContext(id) => {
                write!(f, "undefined compressed context {id}")
            }
            Self::UnknownTermId(id) => write!(f, "unknown CBOR-LD term ID {id}"),
            Self::UnknownCompressedValue(id) => write!(f, "unknown compressed value {id}"),
            Self::UnrecognizedBytes(msg) => write!(f, "unrecognized bytes: {msg}"),
            Self::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
            Self::UnsupportedValue(msg) => write!(f, "unsupported value: {msg}"),
        }
    }
}

impl std::error::Error for Error {}