Struct fixt::Fixturator

source ·
pub struct Fixturator<Item, Curve> {
    pub curve: Curve,
    pub index: usize,
    /* private fields */
}
Expand description

the Fixturator is the struct that we wrap in our FooFixturator newtypes to impl Iterator over each combination of Item and Curve needs its own Iterator implementation for Fixturator Item is the Foo type of FooFixturator, i.e. the type of thing we are generating examples of Curve represents some algorithm capable of generating fixtures the Item is PhantomData because it simply represents a type to output the Curve must be provided when the Fixturator is constructed to allow for paramaterized curves this is most easily handled in most cases with the fixturator! and newtype_fixturator! macros

The inner index is always a single usize. It can be ignored, e.g. in the case of Unpredictable implementations based on rand::random(). If it is used it should be incremented by 1 and/or wrapped back to 0 to derive returned values. Ideally the Curve should allow for efficient calculation of a fixture from any given index, e.g. a fibbonacci curve would be a bad idea as it requires sequential/recursive calculations to reach any specific index, c.f. the direct multiplication in the step function above. Following this standard allows for wrapper structs to delegate their curves to the curves of their inner types by constructing an inner Fixturator directly with the outer index passed in. If we can always assume the inner fixturators can be efficiently constructed at any index this allows us to efficiently compose fixturators. See newtype_fixturator! macro defined below for an example of this.

Fixturator implements Clone for convenience but note that this will clone the current index.

Fixturators are lazy and infinite, they must never fail to iterate That is to say, calling fixturator.next().unwrap() must be safe to do and never panic This makes the external interface as easy to compose as possible when building up Fixturators over complex data types that include different curves with various periods. For example, the Predictable bool sequence cycles between true/false with period of 2 while the Predictable string sequence has 10 sample strings that it iterates over. We want to be able to easily support Fixturators over structs containing both string and bool fields, so we wrap the inner Fixturator sequences to keep producing bools and Strings for as needed (rather than forcing the outer struct to stop after 2 bools or manually implement ad-hoc wrapping). Wrapping logic may be subtle, e.g. mapping between a usize index and a u8 Item where the max values do not align, so it is best to centralise the wrapping behaviour inside the Iterator implementations for each <Item, Curve> combination. If you are implementing an iteration over some finite sequence then wrap the iteration back to the start of the sequence once the index exceeds the sequence’s bounds or reset the index to 0 after seq.len() iterations. essentially, the iteration of a fixturator should work like some_iter.cycle()

Fields§

§curve: Curve§index: usize

Implementations§

source§

impl<Curve, Item> Fixturator<Item, Curve>

source

pub fn new(curve: Curve, start: usize) -> Self

constructs a Fixturator of type <Item, Curve> from a Curve and starting index raw calls are a little verbose, e.g. Fixturator::<u32, Predictable>::new(Predictable, 0) the starting index is exposed to facilitate wrapper structs to delegate their indexes to internal Fixturators See newtype_fixturator! macro below for an example of this

Auto Trait Implementations§

§

impl<Item, Curve> RefUnwindSafe for Fixturator<Item, Curve>where
    Curve: RefUnwindSafe,
    Item: RefUnwindSafe,

§

impl<Item, Curve> Send for Fixturator<Item, Curve>where
    Curve: Send,
    Item: Send,

§

impl<Item, Curve> Sync for Fixturator<Item, Curve>where
    Curve: Sync,
    Item: Sync,

§

impl<Item, Curve> Unpin for Fixturator<Item, Curve>where
    Curve: Unpin,
    Item: Unpin,

§

impl<Item, Curve> UnwindSafe for Fixturator<Item, Curve>where
    Curve: UnwindSafe,
    Item: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V