[][src]Struct caith::Roller

pub struct Roller(_);

An object holding the query.

It has no advantage compare to free function that would take &str as parameter (like previous version) but it provides a stable API for the day pest can have a Send type as the parse result.

see Pest's issue and Forum topic

Implementations

impl Roller[src]

pub fn new(input: &str) -> Result<Self>[src]

Store the input

As of version 2.0.0, it always returns Ok(Self).

This is to have a stable API for further optimization where the parsing is done here (so it can fail) and saved, see Roller documentation above.

pub fn roll(&self) -> Result<RollResult>[src]

Evaluate and roll the dices with default Rng source (rand::thread_rng())

pub fn roll_with<RNG: Rng>(&self, rng: &mut RNG) -> Result<RollResult>[src]

Evaluate and roll the dices with provided rng source

pub fn dices(&self) -> Result<Dices<'_>>[src]

Get an iterator on the dices in the expression

Examples

use caith::Roller;

let r = Roller::new("1d6 + 1d4 + 1d10 + 1d20").unwrap();
assert_eq!(vec!["1d6", "1d4", "1d10", "1d20"], r.dices().expect("Error on parse").collect::<Vec<_>>());

pub fn as_str(&self) -> &str[src]

Give back the query string

pub fn trim_reason(&mut self)[src]

Removes the reason from the Roller

Trait Implementations

impl Clone for Roller[src]

impl Debug for Roller[src]

Auto Trait Implementations

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>,