@@ -328,3 +328,327 @@ This project is licensed under either of
328
328
http://opensource.org/licenses/MIT )
329
329
330
330
at your option.
331
+ =======
332
+ # Fake
333
+
334
+ ![ Rust] ( https://github.com/cksac/fake-rs/workflows/Rust/badge.svg )
335
+ [ ![ Docs Status] ( https://docs.rs/fake/badge.svg )] ( https://docs.rs/fake )
336
+ [ ![ Latest Version] ( https://img.shields.io/crates/v/fake.svg )] ( https://crates.io/crates/fake )
337
+
338
+ A Rust library for generating fake data.
339
+
340
+ ## Installation
341
+
342
+ Default:
343
+
344
+ ``` toml
345
+ [dependencies ]
346
+ fake = { version = " 2.9.2" , features = [" derive" ] }
347
+ ```
348
+
349
+ Available features:
350
+
351
+ - ` derive ` : if you want to use ` #[derive(Dummy)] `
352
+ - supported crates feature flags:
353
+ - ` chrono `
354
+ - ` chrono-tz `
355
+ - ` http `
356
+ - ` uuid `
357
+ - ` bigdecimal ` (via ` bigdecimal-rs ` )
358
+ - ` rust_decimal `
359
+ - ` random_color `
360
+ - ` geo `
361
+ - ` semver `
362
+ - ` serde_json `
363
+ - ` time `
364
+ - ` zerocopy `
365
+ - ` glam `
366
+ - ` always-true-rng ` : expose AlwaysTrueRng
367
+ - ` maybe-non-empty-collections ` : allow to use AlwaysTrueRng to generate non-empty collections
368
+
369
+ ## Usage
370
+
371
+ ``` rust
372
+ use fake :: {Dummy , Fake , Faker };
373
+ use rand :: rngs :: StdRng ;
374
+ use rand :: SeedableRng ;
375
+
376
+ #[derive(Debug , Dummy )]
377
+ pub struct Foo {
378
+ #[dummy(faker = " 1000..2000" )]
379
+ order_id : usize ,
380
+ customer : String ,
381
+ paid : bool ,
382
+ }
383
+
384
+ #[derive(Debug , Dummy )]
385
+ struct Bar <T > {
386
+ field : Vec <T >,
387
+ }
388
+
389
+ fn main () {
390
+ // type derived Dummy
391
+ let f : Foo = Faker . fake ();
392
+ println! (" {:?}" , f );
393
+
394
+ let b : Bar <Foo > = Faker . fake ();
395
+ println! (" {:?}" , b );
396
+
397
+ // using `Faker` to generate default fake value of given type
398
+ let tuple = Faker . fake :: <(u8 , u32 , f32 )>();
399
+ println! (" tuple {:?}" , tuple );
400
+ println! (" String {:?}" , Faker . fake :: <String >());
401
+
402
+ // types U can used to generate fake value T, if `T: Dummy<U>`
403
+ println! (" String {:?}" , (8 .. 20 ). fake :: <String >());
404
+ println! (" u32 {:?}" , (8 .. 20 ). fake :: <u32 >());
405
+
406
+ // using `faker` module with locales
407
+ use fake :: faker :: name :: raw :: * ;
408
+ use fake :: locales :: * ;
409
+
410
+ let name : String = Name (EN ). fake ();
411
+ println! (" name {:?}" , name );
412
+
413
+ let name : String = Name (ZH_TW ). fake ();
414
+ println! (" name {:?}" , name );
415
+
416
+ // using convenient function without providing locale
417
+ use fake :: faker :: lorem :: en :: * ;
418
+ let words : Vec <String > = Words (3 .. 5 ). fake ();
419
+ println! (" words {:?}" , words );
420
+
421
+ // using macro to generate nested collection
422
+ let name_vec = fake :: vec! [String as Name (EN ); 4 , 3 .. 5 , 2 ];
423
+ println! (" random nested vec {:?}" , name_vec );
424
+
425
+ // fixed seed rng
426
+ let seed = [
427
+ 1 , 0 , 0 , 0 , 23 , 0 , 0 , 0 , 200 , 1 , 0 , 0 , 210 , 30 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
428
+ 0 , 0 , 0 , 0 ,
429
+ ];
430
+ let ref mut r = StdRng :: from_seed (seed );
431
+ for _ in 0 .. 5 {
432
+ let v : usize = Faker . fake_with_rng (r );
433
+ println! (" value from fixed seed {}" , v );
434
+ }
435
+ }
436
+ ```
437
+
438
+ # Fakers with locale
439
+
440
+ ## Lorem
441
+
442
+ ``` rust
443
+ Word ();
444
+ Words (count : Range <usize >);
445
+ Sentence (count : Range <usize >);
446
+ Sentences (count : Range <usize >);
447
+ Paragraph (count : Range <usize >);
448
+ Paragraphs (count : Range <usize >);
449
+ ```
450
+
451
+ ## Name
452
+
453
+ ``` rust
454
+ FirstName ();
455
+ LastName ();
456
+ Title ();
457
+ Suffix ();
458
+ Name ();
459
+ NameWithTitle ();
460
+ ```
461
+
462
+ ## Number
463
+
464
+ ``` rust
465
+ Digit ();
466
+ NumberWithFormat <'a >(fmt : & 'a str );
467
+ ```
468
+
469
+ ## Boolean
470
+
471
+ ``` rust
472
+ Boolean (ratio : u8 );
473
+ ```
474
+
475
+ ## Internet
476
+
477
+ ``` rust
478
+ FreeEmailProvider ();
479
+ DomainSuffix ();
480
+ FreeEmail ();
481
+ SafeEmail ();
482
+ Username ();
483
+ Password (len_range : Range <usize >);
484
+ IPv4 ();
485
+ IPv6 ();
486
+ IP ();
487
+ MACAddress ();
488
+ UserAgent ();
489
+ ```
490
+
491
+ ## HTTP
492
+
493
+ ``` rust
494
+ RfcStatusCode ();
495
+ ValidStatusCode ();
496
+ ```
497
+
498
+ ## Color
499
+
500
+ ``` rust
501
+ HexColor ();
502
+ RgbColor ();
503
+ RgbaColor ();
504
+ HslColor ();
505
+ HslaColor ();
506
+ Color ();
507
+ ```
508
+
509
+ ## Company
510
+
511
+ ``` rust
512
+ CompanySuffix ();
513
+ CompanyName ();
514
+ Buzzword ();
515
+ BuzzwordMiddle ();
516
+ BuzzwordTail ();
517
+ CatchPhase ();
518
+ BsVerb ();
519
+ BsAdj ();
520
+ BsNoun ();
521
+ Bs ();
522
+ Profession ();
523
+ Industry ();
524
+ ```
525
+
526
+ ## Currency
527
+
528
+ ``` rust
529
+ CurrencyCode ();
530
+ CurrencyName ();
531
+ CurrencySymbol ();
532
+ ```
533
+
534
+ ## Creditcard
535
+
536
+ ``` rust
537
+ CreditCardNumber ();
538
+ ```
539
+
540
+ ## Address
541
+
542
+ ``` rust
543
+ CityPrefix ();
544
+ CitySuffix ();
545
+ CityName ();
546
+ CountryName ();
547
+ CountryCode ();
548
+ StreetSuffix ();
549
+ StreetName ();
550
+ TimeZone ();
551
+ StateName ();
552
+ StateAbbr ();
553
+ SecondaryAddressType ();
554
+ SecondaryAddress ();
555
+ ZipCode ();
556
+ PostCode ();
557
+ BuildingNumber ();
558
+ Latitude ();
559
+ Longitude ();
560
+ Geohash (precision : u8 );
561
+ ```
562
+
563
+ ## Administrative
564
+
565
+ ``` rust
566
+ HealthInsuranceCode ();
567
+ ```
568
+
569
+ ## Automotive
570
+
571
+ ``` rust
572
+ LicencePlate ();
573
+ ```
574
+
575
+ ## Barcode
576
+
577
+ ``` rust
578
+ Isbn ();
579
+ Isbn13 ();
580
+ Isbn10 ();
581
+ ```
582
+
583
+ ## Phone Number
584
+
585
+ ``` rust
586
+ PhoneNumber ();
587
+ CellNumber ();
588
+ ```
589
+
590
+ ## Date/Time
591
+
592
+ ``` rust
593
+ Time ();
594
+ Date ();
595
+ DateTime ();
596
+ Duration ();
597
+ DateTimeBefore (dt : DateTime <Utc >);
598
+ DateTimeAfter (dt : DateTime <Utc >);
599
+ DateTimeBetween (start : DateTime <Utc >, end : DateTime <Utc >);
600
+ ```
601
+
602
+ ## Filesystem
603
+
604
+ ``` rust
605
+ FilePath ();
606
+ FileName ();
607
+ FileExtension ();
608
+ DirPath ();
609
+ ```
610
+
611
+ ### Finance
612
+
613
+ ``` rust
614
+ Bic ();
615
+ Isin ();
616
+ ```
617
+
618
+ ### UUID
619
+
620
+ ``` rust
621
+ UUIDv1 ();
622
+ UUIDv3 ();
623
+ UUIDv4 ();
624
+ UUIDv5 ();
625
+ ```
626
+
627
+ ### Decimal
628
+
629
+ ``` rust
630
+ Decimal ();
631
+ PositiveDecimal ();
632
+ NegativeDecimal ();
633
+ NoDecimalPoints ();
634
+ ```
635
+
636
+ ### Bigdecimal
637
+
638
+ ``` rust
639
+ BigDecimal ();
640
+ PositiveBigDecimal ();
641
+ NegativeBigDecimal ();
642
+ NoBigDecimalPoints ();
643
+ ```
644
+
645
+ # LICENSE
646
+
647
+ This project is licensed under either of
648
+
649
+ - Apache License, Version 2.0, ([ LICENSE-APACHE] ( LICENSE-APACHE ) or
650
+ http://www.apache.org/licenses/LICENSE-2.0 )
651
+ - MIT license ([ LICENSE-MIT] ( LICENSE-MIT ) or
652
+ http://opensource.org/licenses/MIT )
653
+
654
+ at your option.
0 commit comments