[][src]Enum critfail::Roll

pub enum Roll {
    Check(Check),
    Damage(Damage),
    Attack(Attack),
}

Any kind of roll—either a check, damage, or attack roll.

This struct is useful when parsing a roll expression if you don't know what type of roll expression it will be.

use critfail::{RollExpression, Roll};

let check = Roll::new("r-3").unwrap();
let check_outcome = check.roll();
print!("{}", check_outcome); // eg. "11"
print!("{:?}", check_outcome); // eg. "(14)-3"

let damage = Roll::new("2d8+6").unwrap();
let damage_outcome = damage.roll();
print!("{}", damage_outcome); // eg. "13"
print!("{:?}", damage_outcome); // eg. "[2+5]+6"

let attack = Roll::new("r+1?2d6+4").unwrap();
let attack_outcome = attack.roll();
print!("{}", attack_outcome); // eg. "10 ? 16"
print!("{:?}", attack_outcome); // eg. "(9)+1 ? [6+6]+4"

Variants

Check(Check)

A Roll containing a Check roll.

Damage(Damage)

A Roll containing a Damage roll.

Attack(Attack)

A Roll containing an Attack roll.

Implementations

impl Roll[src]

pub fn is_check(&self) -> bool[src]

Return true if this Roll is a check roll.

use critfail::{RollExpression, Roll};

assert_eq!(Roll::new("r+3").unwrap().is_check(), true);
assert_eq!(Roll::new("2d8+5").unwrap().is_check(), false);
assert_eq!(Roll::new("r+3?2d8+5").unwrap().is_check(), false);

pub fn is_damage(&self) -> bool[src]

Return true if this Roll is a damage roll.

use critfail::{RollExpression, Roll};

assert_eq!(Roll::new("r+3").unwrap().is_damage(), false);
assert_eq!(Roll::new("2d8+5").unwrap().is_damage(), true);
assert_eq!(Roll::new("r+3?2d8+5").unwrap().is_damage(), false);

pub fn is_attack(&self) -> bool[src]

Return true if this Roll is an attack roll.

use critfail::{RollExpression, Roll};

assert_eq!(Roll::new("r+3").unwrap().is_attack(), false);
assert_eq!(Roll::new("2d8+5").unwrap().is_attack(), false);
assert_eq!(Roll::new("r+3?2d8+5").unwrap().is_attack(), true);

Trait Implementations

impl Clone for Roll[src]

impl Debug for Roll[src]

impl From<Attack> for Roll[src]

impl From<Check> for Roll[src]

impl From<Damage> for Roll[src]

impl FromStr for Roll[src]

type Err = ParseError

The associated error which can be returned from parsing.

impl PartialEq<Roll> for Roll[src]

impl RollExpression for Roll[src]

type Outcome = RollOutcome

The roll result type should implement both Display and Debug. Display should print out a consise result for the roll, and Debug should print out the details (eg the value for each rolled die). Read more

impl StructuralPartialEq for Roll[src]

Auto Trait Implementations

impl RefUnwindSafe for Roll

impl Send for Roll

impl Sync for Roll

impl Unpin for Roll

impl UnwindSafe for Roll

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,