Skip to main content

field_cat/
error.rs

1//! Project-wide error type.
2
3/// All errors that can arise in field-cat.
4#[derive(Debug)]
5pub enum Error {
6    /// Attempted to invert zero in the field.
7    DivisionByZero,
8    /// Field element could not be decoded from bytes.
9    InvalidFieldEncoding,
10}
11
12impl core::fmt::Display for Error {
13    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14        match self {
15            Self::DivisionByZero => write!(f, "division by zero"),
16            Self::InvalidFieldEncoding => write!(f, "invalid field element encoding"),
17        }
18    }
19}
20
21impl std::error::Error for Error {
22    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23        match self {
24            Self::DivisionByZero | Self::InvalidFieldEncoding => None,
25        }
26    }
27}