dxfbin 0.1.0

Streaming text DXF to binary DXF converter
Documentation
// SPDX-License-Identifier: ISC
use core::fmt;

/// Errors that can occur during text-to-binary DXF conversion.
///
/// The type parameter `S` is the sink's error type, carried by the
/// [`Sink`](Error::Sink) variant. Defaults to `()` when no sink is involved.
#[derive(Debug)]
pub enum Error<S = ()> {
    /// The sink returned an error.
    Sink(S),
    /// A group code line could not be parsed as a `u16`.
    InvalidGroupCode,
    /// A value line could not be parsed for its expected type.
    InvalidValue,
    /// A hex string in a binary chunk had odd length or invalid digits.
    InvalidHex,
    /// A numeric value line contained invalid UTF-8.
    InvalidUtf8,
}

impl<S: fmt::Debug> fmt::Display for Error<S> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Sink(e) => write!(f, "sink error: {e:?}"),
            Error::InvalidGroupCode => f.write_str("invalid group code"),
            Error::InvalidValue => f.write_str("invalid value"),
            Error::InvalidHex => f.write_str("invalid hex string"),
            Error::InvalidUtf8 => f.write_str("invalid utf-8"),
        }
    }
}

#[cfg(feature = "std")]
impl<S: fmt::Debug> std::error::Error for Error<S> {}