pub struct Notation { /* private fields */ }Expand description
A validated dice expression, such as 2d6+3.
Create one by parsing a string or with Notation::try_new.
§Examples
use rust_roll::notation::Notation;
let notation: Notation = "2d6+3".parse().unwrap();
assert_eq!(notation.count(), 2);
assert_eq!(notation.sides(), 6);
assert!(notation.modifier().is_some());Implementations§
Source§impl Notation
impl Notation
Sourcepub fn try_new(
count: u32,
sides: u32,
modifier: Option<Modifier>,
) -> Result<Self, NotationError>
pub fn try_new( count: u32, sides: u32, modifier: Option<Modifier>, ) -> Result<Self, NotationError>
Creates a notation, checking that count and sides are within bounds.
§Errors
Returns NotationError::Zero if count or sides is zero, or
NotationError::NumberTooLarge if either exceeds MAX_VALUE.
§Examples
use rust_roll::notation::Notation;
let notation = Notation::try_new(2, 6, None).unwrap();
assert_eq!(notation.count(), 2);Sourcepub fn d20(modifier: Option<Modifier>) -> Notation
pub fn d20(modifier: Option<Modifier>) -> Notation
A single d20 with an optional modifier: the default roll for advantage and disadvantage.
§Examples
use rust_roll::notation::Notation;
let notation = Notation::d20(None);
assert_eq!((notation.count(), notation.sides()), (1, 20));Sourcepub fn critical(self) -> Notation
pub fn critical(self) -> Notation
Returns the notation for a critical hit, following the D&D 5e (2014) rules: the number of dice is doubled, while the sides and modifier are unchanged, so the modifier is still applied only once.
The doubled count may exceed MAX_VALUE: a critical 1000d6 becomes
2000d6. This is deliberate, as capping it would change the rule.
§Examples
use rust_roll::notation::Notation;
let notation: Notation = "1d8+2".parse().unwrap();
let critical = notation.critical();
assert_eq!(critical.count(), 2);
assert_eq!(critical.modifier(), notation.modifier());Trait Implementations§
impl Copy for Notation
impl Eq for Notation
impl StructuralPartialEq for Notation
Auto Trait Implementations§
impl Freeze for Notation
impl RefUnwindSafe for Notation
impl Send for Notation
impl Sync for Notation
impl Unpin for Notation
impl UnsafeUnpin for Notation
impl UnwindSafe for Notation
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