pub enum DiceError {
Overflow(String),
InvalidSpec(RollSpec, String),
ParseError {
kind: ParseErrorKind,
input: String,
start: usize,
stop: Option<usize>,
},
SyntaxError {
input: String,
start: usize,
stop: Option<usize>,
expected: Option<String>,
},
TrailingInput {
input: String,
pos: usize,
},
}Expand description
Errors that can occur when parsing or evaluating dice expressions.
This enum covers all possible error conditions, including parse errors, invalid roll specifications, and arithmetic overflow.
§Variants
Overflow: Integer overflow during calculationInvalidSpec: Invalid roll specification (e.g., trying to keep more dice than rolled)ParseError: Error parsing the input stringSyntaxError: Syntax error in the dice expressionTrailingInput: Unexpected characters after the expression
§Examples
use dice_parser::DiceExpr;
// Parse error - invalid syntax
let err = DiceExpr::parse("2d").unwrap_err();
// Syntax error - negative dice count
let err = DiceExpr::parse("-2d6").unwrap_err();
// Trailing input error
let err = DiceExpr::parse("2d6 extra").unwrap_err();Variants§
Overflow(String)
Integer overflow occurred during calculation.
InvalidSpec(RollSpec, String)
Invalid roll specification.
This error occurs when a RollSpec is invalid, such as trying to
keep more dice than were rolled.
ParseError
Parse error with details about what went wrong.
Fields
§
kind: ParseErrorKindThe kind of parse error.
SyntaxError
Syntax error in the dice expression.
Fields
TrailingInput
Unexpected characters found after the expression.
Trait Implementations§
Source§impl Error for DiceError
impl Error for DiceError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<TryFromIntError> for DiceError
impl From<TryFromIntError> for DiceError
Source§fn from(value: TryFromIntError) -> Self
fn from(value: TryFromIntError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for DiceError
impl RefUnwindSafe for DiceError
impl Send for DiceError
impl Sync for DiceError
impl Unpin for DiceError
impl UnwindSafe for DiceError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more