pub enum CalcError {
ParseInt(ParseIntError),
FromUtf8(FromUtf8Error),
SymTab(SymTabError),
}
Expand description
Represents all possible errors that can occur within the calculator.
The CalcError
enum aggregates various error sources encountered
during lexical analysis, parsing, and symbol-table operations.
It implements std::error::Error
via thiserror::Error
, allowing
ergonomic error propagation with the ?
operator.
Each variant wraps a more specific underlying error type.
§Variants
-
CalcError::ParseInt
:
Returned when a numeric literal cannot be parsed into an integer, typically originating fromstd::num::ParseIntError
. -
CalcError::FromUtf8
:
Returned when the input contains invalid UTF-8 byte sequences and cannot be decoded into aString
. -
CalcError::SymTab
:
Wraps an error from the symbol table subsystem (SymTabError
).
§Example
// Example of a parse error bubbling up as CalcError::ParseInt
let result: Result<i64, CalcError> = i64::from_str("notanumber").map_err(CalcError::from);
assert!(matches!(result.unwrap_err(), CalcError::ParseInt(_)));
// Example of a symbol-table error propagation
let sym_err = SymTabError::InvalidIndex { index: 10, len: 3 };
let err = CalcError::from(sym_err);
assert!(matches!(err, CalcError::SymTab(_)));
Variants§
ParseInt(ParseIntError)
An integer literal could not be parsed from its string representation.
Typically originates from std::num::ParseIntError
.
FromUtf8(FromUtf8Error)
Failed to decode UTF-8 bytes from input.
Wraps a std::string::FromUtf8Error
.
SymTab(SymTabError)
A symbol-table operation failed.
Wraps a SymTabError
produced by symbol-table lookups or updates.