pub enum A3Error {
Parse(Error),
Serialize(Error),
Validate(Vec<String>),
}Expand description
The single error type returned by every fallible function in this crate.
In Rust, errors are values — there are no exceptions. Every function that
can fail returns Result<T, A3Error>, which is either Ok(value) or
Err(A3Error::...). The caller decides how to handle it.
#[derive(Debug)] lets you print the error with {:?} formatting.
#[derive(Error)] (from thiserror) implements std::error::Error for us.
Variants§
Parse(Error)
Returned when the input string is not valid JSON.
#[error("...")] defines the human-readable message produced by
.to_string() or the {} format specifier.
{0} refers to the first (and only) field of this variant by position.
serde_json::Error is the underlying parse error from the JSON library.
#[from] implements From<serde_json::Error> for A3Error automatically,
enabling the ? operator to convert deserialization errors into this
variant without an explicit .map_err(...) call.
Serialize(Error)
Returned when a validated crate::A3 cannot be serialized to JSON.
In practice this variant is unreachable for well-typed A3 values, but
it is kept distinct from A3Error::Parse so that error messages
accurately reflect the failure mode — serialization, not parsing.
Validate(Vec<String>)
Returned when input is structurally valid JSON but violates A3 rules.
We collect all validation errors into a Vec<String> so that a
caller sees every problem at once, not just the first one encountered.
{0:#?} uses the “alternate” debug formatter, which prints each
element on its own line — readable for a list of error messages.
Trait Implementations§
Source§impl Error for A3Error
impl Error for A3Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()