Skip to main content

Faker

Struct Faker 

Source
pub struct Faker { /* private fields */ }
Expand description

The seedable random-value source every template’s random defaults draw from.

A SplitMix64 generator (Steele, Lea & Flood’s public-domain algorithm), implemented here rather than depended upon — see the crate docs for the fake-vs-rand-vs-in-crate evaluation. The output sequence for a given seed is pinned by test in this crate: two Faker::seeded instances with the same seed produce identical values, on every platform, forever — that is the determinism switch’s whole contract.

Not cryptographic, and not meant to be: this generates test data.

Implementations§

Source§

impl Faker

Source

pub fn seeded(seed: u64) -> Self

A faker whose entire output is determined by seed — the reproducibility switch. Same seed, same values, always.

Source

pub fn from_entropy() -> Self

A faker seeded from wall-clock entropy plus a process-global counter — what create/create_many use when the caller does not care about reproducing the run.

Source

pub fn next_u64(&mut self) -> u64

The next raw 64-bit value.

Source

pub fn below(&mut self, n: u64) -> u64

A value in 0..n. The multiply-shift reduction carries a negligible modulo bias — acceptable for test data, and deterministic, which is what matters here.

§Panics

If n is zero — an empty range has no value to produce.

Source

pub fn i64_in(&mut self, lo: i64, hi: i64) -> i64

A value in lo..=hi.

§Panics

If lo > hi.

Source

pub fn i32_in(&mut self, lo: i32, hi: i32) -> i32

A value in lo..=hi, i32-typed for dialects whose integer is 32-bit.

§Panics

If lo > hi.

Source

pub fn alnum(&mut self, len: usize) -> String

A random lowercase-alphanumeric string of len characters — "user-{alnum}"-style default values are built from this.

Trait Implementations§

Source§

impl Clone for Faker

Source§

fn clone(&self) -> Faker

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Faker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Faker

§

impl RefUnwindSafe for Faker

§

impl Send for Faker

§

impl Sync for Faker

§

impl Unpin for Faker

§

impl UnsafeUnpin for Faker

§

impl UnwindSafe for Faker

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.