Skip to main content

Faker

Struct Faker 

Source
pub struct Faker;
Expand description

Main Faker struct providing access to all generators

Implementations§

Source§

impl Faker

Source

pub fn config() -> FakerConfig

Get the current Faker configuration

Source

pub fn set_seed(seed: u64)

Set the random seed for deterministic output

Examples found in repository?
examples/advanced_features.rs (line 15)
8fn main() {
9    println!("=== Faker-Rust Advanced Features Examples ===\n");
10
11    // Demonstrate deterministic generation with seed
12    println!("🎲 DETERMINISTIC GENERATION (Seeded):");
13    println!("Setting seed to 12345...\n");
14    
15    Faker::set_seed(12345);
16    let name1 = name::name();
17    let email1 = internet::email(None, None, None);
18    let city1 = address::city();
19    
20    println!("First run:");
21    println!("  Name:   {}", name1);
22    println!("  Email:  {}", email1);
23    println!("  City:   {}", city1);
24    println!();
25
26    // Reset with same seed - should produce same results
27    Faker::set_seed(12345);
28    let name2 = name::name();
29    let email2 = internet::email(None, None, None);
30    let city2 = address::city();
31    
32    println!("Second run (same seed):");
33    println!("  Name:   {}", name2);
34    println!("  Email:  {}", email2);
35    println!("  City:   {}", city2);
36    println!();
37
38    // Verify they're the same
39    if name1 == name2 && email1 == email2 && city1 == city2 {
40        println!("✅ SUCCESS: Same seed produces identical results!");
41    } else {
42        println!("❌ ERROR: Results differ despite same seed");
43    }
44    println!();
45
46    // Different seed produces different results
47    println!("Different seed (54321):");
48    Faker::set_seed(54321);
49    println!("  Name:   {}", name::name());
50    println!("  Email:  {}", internet::email(None, None, None));
51    println!("  City:   {}", address::city());
52    println!();
53
54    // Batch generation
55    println!("📊 BATCH GENERATION:");
56    println!("Generating 5 random companies:");
57    for i in 1..=5 {
58        println!("  {}. {} - {}", i, company::name(), company::catch_phrase());
59    }
60    println!();
61
62    // Generate fake user profiles
63    println!("👤 FAKE USER PROFILES:");
64    for i in 1..=3 {
65        println!("User {}:", i);
66        println!("  Name:     {}", name::name());
67        println!("  Email:    {}", internet::email(None, None, None));
68        println!("  Username: {}", internet::username(None));
69        println!("  Address:  {}", address::street_address());
70        println!("  Company:  {}", company::name());
71        println!();
72    }
73}
More examples
Hide additional examples
examples/basic_usage.rs (line 58)
9fn main() {
10    println!("=== Faker-Rust Basic Usage Examples ===\n");
11
12    // Name generators
13    println!("👤 NAMES:");
14    println!("  Full Name:      {}", name::name());
15    println!("  First Name:     {}", name::first_name());
16    println!("  Last Name:      {}", name::last_name());
17    println!("  Name with Middle: {}", name::name_with_middle());
18    println!("  Prefix:         {}", name::prefix());
19    println!("  Suffix:         {}", name::suffix());
20    println!("  Initials (3):   {}", name::initials(3));
21    println!();
22
23    // Address generators
24    println!("📍 ADDRESSES:");
25    println!("  Street Address: {}", address::street_address());
26    println!("  Street Name:    {}", address::street_name());
27    println!("  City:           {}", address::city());
28    println!("  ZIP Code:       {}", address::zip_code());
29    println!("  Country:        {}", address::country());
30    println!("  Secondary:      {}", address::secondary_address());
31    println!();
32
33    // Internet generators
34    println!("🌐 INTERNET:");
35    println!("  Email:          {}", internet::email(None, None, None));
36    println!("  Domain:         {}", internet::domain_name(false, None));
37    println!("  URL:            {}", internet::url(None, None, None));
38    println!("  Username:       {}", internet::username(None));
39    println!("  Password:       {}", internet::password(12, 20, true, true));
40    println!();
41
42    // Phone numbers
43    println!("📞 PHONE NUMBERS:");
44    println!("  Phone:          {}", phone_number::phone_number());
45    println!("  Cell Phone:     {}", phone_number::cell_phone());
46    println!();
47
48    // Company generators
49    println!("🏢 COMPANIES:");
50    println!("  Company Name:   {}", company::name());
51    println!("  Industry:       {}", company::industry());
52    println!("  Catch Phrase:   {}", company::catch_phrase());
53    println!("  BS:             {}", company::bs());
54    println!();
55
56    // Seeded generation for reproducibility
57    println!("🎲 SEEDED GENERATION (Deterministic):");
58    Faker::set_seed(12345);
59    println!("  Seeded Name 1:  {}", name::name());
60    Faker::set_seed(12345);
61    println!("  Seeded Name 2:  {}", name::name());
62    println!("  (Same seed = Same output)");
63}

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

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

Source§

fn vzip(self) -> V