pub struct Roller(_);
Expand description
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
sourceimpl Roller
impl Roller
sourcepub fn new(input: &str) -> Result<Self>
pub fn new(input: &str) -> Result<Self>
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.
sourcepub fn roll(&self) -> Result<RollResult>
pub fn roll(&self) -> Result<RollResult>
Evaluate and roll the dices with default Rng source (rand::thread_rng()
)
sourcepub fn roll_with<RNG: Rng>(&self, rng: &mut RNG) -> Result<RollResult>
pub fn roll_with<RNG: Rng>(&self, rng: &mut RNG) -> Result<RollResult>
Evaluate and roll the dices with provided rng source
sourcepub fn roll_with_source<RNG: DiceRollSource>(
&self,
rng: &mut RNG
) -> Result<RollResult>
pub fn roll_with_source<RNG: DiceRollSource>(
&self,
rng: &mut RNG
) -> Result<RollResult>
Evaluate and roll the dice with provided dice roll source
sourcepub fn dices(&self) -> Result<Dices<'_>>
pub fn dices(&self) -> Result<Dices<'_>>
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<_>>());
sourcepub fn trim_reason(&mut self)
pub fn trim_reason(&mut self)
Removes the reason from the Roller
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Roller
impl Send for Roller
impl Sync for Roller
impl Unpin for Roller
impl UnwindSafe for Roller
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more