#[non_exhaustive]pub enum Error {
Show 13 variants
Parse {
input: String,
position: usize,
message: String,
},
InvalidNumber {
input: String,
},
UnknownUnit {
symbol: String,
suggestions: Vec<String>,
},
AmbiguousSymbol {
symbol: String,
candidates: Vec<String>,
},
AmbiguousExpression {
input: String,
message: String,
},
DimensionMismatch {
from: Dim,
to: Dim,
},
KindMismatch {
from: Kind,
to: Kind,
operation: &'static str,
suggestions: Vec<String>,
},
Overflow {
operation: &'static str,
},
DivisionByZero,
LengthMismatch {
input: usize,
output: usize,
},
Refused {
reason: String,
suggestions: Vec<String>,
},
InvalidDefinition {
symbol: String,
message: String,
},
DuplicateSymbol {
symbol: String,
},
}Expand description
Everything that can go wrong in dimvexa. Library code never panics: every fallible operation returns this type.
Each variant has a stable, documented machine-readable code (see Error::code and
Error::ALL_CODES). The enum is #[non_exhaustive]: new variants may be added in
minor releases, codes are never renamed within a schema version.
§Examples
use dimvexa_core::{Error, Ratio};
let err = Ratio::new(1, 0).unwrap_err();
assert_eq!(err.code(), "division_by_zero");
assert!(matches!(err, Error::DivisionByZero));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Parse
Syntax error in a unit expression or number. Code parse_error.
Fields
InvalidNumber
A number could not be read. Code invalid_number.
UnknownUnit
The symbol is not in the registry. Code unknown_unit.
Fields
AmbiguousSymbol
The bare symbol has several meanings and no profile resolves it.
Code ambiguous_symbol.
Fields
AmbiguousExpression
The expression is syntactically valid but its meaning depends on operator
precedence conventions. Code ambiguous_expression.
Fields
DimensionMismatch
The two units measure different physical dimensions. Code dimension_mismatch.
KindMismatch
The two units have the same dimension but incompatible kinds, for example an
absolute temperature and a temperature difference. Code kind_mismatch.
Fields
Overflow
A checked integer operation overflowed. Code overflow.
DivisionByZero
Division by zero in exact arithmetic. Code division_by_zero.
LengthMismatch
Input and output slices have different lengths. Code length_mismatch.
Refused
The operation is deliberately not supported because it would require guessing.
Code refused.
Fields
InvalidDefinition
A unit definition is inconsistent. Code invalid_definition.
DuplicateSymbol
A symbol or alias is registered twice. Code duplicate_symbol.
Implementations§
Source§impl Error
impl Error
Sourcepub const ALL_CODES: &'static [&'static str]
pub const ALL_CODES: &'static [&'static str]
Every stable machine-readable error code, in declaration order.
Sourcepub const fn code(&self) -> &'static str
pub const fn code(&self) -> &'static str
The stable machine-readable code of this error.
§Examples
use dimvexa_core::Error;
let e = Error::Overflow { operation: "mul" };
assert_eq!(e.code(), "overflow");
assert!(Error::ALL_CODES.contains(&e.code()));Sourcepub fn suggestions(&self) -> &[String]
pub fn suggestions(&self) -> &[String]
Everything the error recommends instead: close matches for an unknown unit, the explicit
symbols for an ambiguous one, and the difference unit (delta_K, …) for a refused or
mismatched temperature operation. Empty if the error has no recommendation.
§Examples
use dimvexa_core::Error;
let e = Error::UnknownUnit { symbol: "PSI".into(), suggestions: vec!["psi".into()] };
assert_eq!(e.suggestions(), ["psi"]);
assert!(Error::DivisionByZero.suggestions().is_empty());Sourcepub fn candidates(&self) -> &[String]
pub fn candidates(&self) -> &[String]
Candidate symbols attached to the error, if any (ambiguous or unknown symbols).
Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · 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()