Skip to main content

Variables

Struct Variables 

Source
pub struct Variables<T> { /* private fields */ }
Expand description

A pool of previously generated values.

Implementations§

Source§

impl<T> Variables<T>

Source

pub fn is_empty(&self) -> bool

Returns true if no variables are in the pool.

Source

pub fn len(&self) -> usize

Number of variables currently in the pool.

Source

pub fn add(&mut self, v: T)

Add a value to the pool.

Examples found in repository?
examples/ledger.rs (line 53)
50    fn create_account(&mut self, tc: TestCase) {
51        let account = tc.draw(gs::text().min_size(1));
52        tc.note(&format!("create account '{}'", account.clone()));
53        self.accounts.add(account);
54    }
Source

pub fn draw(&self) -> &T

Draw a reference to a value from the pool (without removing it).

Calls assume(false) if the pool is empty.

Examples found in repository?
examples/ledger.rs (line 58)
57    fn credit(&mut self, tc: TestCase) {
58        let account = self.accounts.draw().clone();
59        let amount = tc.draw(gs::integers::<i64>().min_value(0).max_value(LIMIT));
60        tc.note(&format!("credit '{}' with {}", account.clone(), amount));
61        self.ledger.credit(account, amount);
62    }
63
64    #[rule]
65    fn transfer(&mut self, tc: TestCase) {
66        let from = self.accounts.draw().clone();
67        let to = self.accounts.draw().clone();
68        let amount = tc.draw(gs::integers::<i64>().min_value(0).max_value(LIMIT));
69        tc.note(&format!(
70            "transfer '{}' from {} to {}",
71            amount,
72            from.clone(),
73            to.clone()
74        ));
75        self.ledger.transfer(from, to, amount);
76    }
Source

pub fn consume(&mut self) -> T

Remove and return a value from the pool.

Calls assume(false) if the pool is empty.

Auto Trait Implementations§

§

impl<T> !Freeze for Variables<T>

§

impl<T> !RefUnwindSafe for Variables<T>

§

impl<T> Send for Variables<T>
where T: Send,

§

impl<T> !Sync for Variables<T>

§

impl<T> Unpin for Variables<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Variables<T>

§

impl<T> !UnwindSafe for Variables<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.