Enum DataType

Source
#[non_exhaustive]
pub enum DataType {
Show 149 variants Address, FrenchAddress, FrenchPostCode, FrenchStreet, Latitude, LatitudeLongitude, Longitude, StreetNumber, UkAddress, UkPostCode, HexColour, HslaColour, HslColour, RgbaColour, RgbColour, DirPath, FileName, FilePath, Ipv4, Ipv6, MacAddress, Semver, SemverStable, SemverUnstable, Bic, Iban, Isin, RandomIsbn10, RandomIsbn13, FamousPerson, CreditCard, Email, FrenchEmail, FrenchLicencePlate, FrenchPhoneNumber, NhsNumber, Password, PhoneNumber, SecuriteSociale, UkLicencePlate, UkPhoneNumber, AlphanumericCapitalChar, AlphanumericChar, Boolean, CapitalChar, Digit, LowerChar, Number, Sentence, Paragraph, Animal, Mammal, Bird, Insect, Fishe, Amphibian, Reptile, Mollusc, AnimalType, MythologicalCreature, LiteraryGenre, ArchitecturalStyle, MusicalGenre, MusicalInstrument, ColourName, CurrencyName, CurrencySymbol, CurrencyCode, DaysOfWeek, Month, DaysOfWeekAbbr, MonthsAbbr, TimeZone, TimeUnit, AmPm, SchoolSubject, AcademicDiscipline, DegreesTitle, University, Sport, FamousFrenchStreet, FrenchRoadType, FrenchCounty, FrenchRiver, HistoricalBattle, EmailDomain, OpenSourceApp, TopLevelDomain, UserAgent, HttpStatusCode, MimeType, NameTitle, FirstName, FrenchFirstName, FrenchLastName, LastName, Painter, Writer, Composer, Mathematician, Physician, Biologist, ComputerScientist, Philosopher, ProgrammingLanguage, ProgrammingParadigm, EditorColourTheme, ItDomain, FileExtension, ChemicalElement, MathematicalFunction, TypesOfCloud, Constellation, Planet, Star, Galaxy, UkCountyCode, UkPostcodeArea, UkCounty, UkCity, UkRoadType, UkRiver, UkStreet, UsStateAbbr, UsState, UsRoad, UsRoadType, Word, Job, CompanyName, ItCompanyName, EnergyCompanyName, FinanceCompanyName, RetailCompanyName, FoodCompanyName, TravelCompanyName, ConstructionCompanyName, MediaCompanyName, TelecomCompanyName, BioCompanyName, CarBrand, AirDefenseCompanyName, ClothingCompanyName, Country, City, Continent, CountryCode, Street, River,
}
Expand description

Representation of type that can be generated randomly.

There are two types of generated data: some are hard-coded with a list of possible values, others are produced by formulas. Both are usable the same way. If you don’t want to load all the possible values for all the types, you can choose to enable the data types you want (all features are enabled by default).

§Examples

use random_data::*;
let mut generator = DataGenerator::new();

#[cfg(feature = "datetime")]
{
    let random_month = DataType::Month.random(&mut generator);
    println!("{random_month}");
}

#[cfg(feature = "address")]
{
    let random_address = DataType::Address.random(&mut generator);
    println!("{random_address}");
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Address

§

FrenchAddress

§

FrenchPostCode

§

FrenchStreet

§

Latitude

§

LatitudeLongitude

§

Longitude

§

StreetNumber

§

UkAddress

§

UkPostCode

§

HexColour

§

HslaColour

§

HslColour

§

RgbaColour

§

RgbColour

§

DirPath

§

FileName

§

FilePath

§

Ipv4

§

Ipv6

§

MacAddress

§

Semver

§

SemverStable

§

SemverUnstable

§

Bic

§

Iban

§

Isin

§

RandomIsbn10

§

RandomIsbn13

§

FamousPerson

§

CreditCard

§

Email

§

FrenchEmail

§

FrenchLicencePlate

§

FrenchPhoneNumber

§

NhsNumber

§

Password

§

PhoneNumber

§

SecuriteSociale

§

UkLicencePlate

§

UkPhoneNumber

§

AlphanumericCapitalChar

§

AlphanumericChar

§

Boolean

§

CapitalChar

§

Digit

§

LowerChar

§

Number

§

Sentence

§

Paragraph

§

Animal

§

Mammal

§

Bird

§

Insect

§

Fishe

§

Amphibian

§

Reptile

§

Mollusc

§

AnimalType

§

MythologicalCreature

§

LiteraryGenre

§

ArchitecturalStyle

§

MusicalGenre

§

MusicalInstrument

§

ColourName

§

CurrencyName

§

CurrencySymbol

§

CurrencyCode

§

DaysOfWeek

§

Month

§

DaysOfWeekAbbr

§

MonthsAbbr

§

TimeZone

§

TimeUnit

§

AmPm

§

SchoolSubject

§

AcademicDiscipline

§

DegreesTitle

§

University

§

Sport

§

FamousFrenchStreet

§

FrenchRoadType

§

FrenchCounty

§

FrenchRiver

§

HistoricalBattle

§

EmailDomain

§

OpenSourceApp

§

TopLevelDomain

§

UserAgent

§

HttpStatusCode

§

MimeType

§

NameTitle

§

FirstName

§

FrenchFirstName

§

FrenchLastName

§

LastName

§

Painter

§

Writer

§

Composer

§

Mathematician

§

Physician

§

Biologist

§

ComputerScientist

§

Philosopher

§

ProgrammingLanguage

§

ProgrammingParadigm

§

EditorColourTheme

§

ItDomain

§

FileExtension

§

ChemicalElement

§

MathematicalFunction

§

TypesOfCloud

§

Constellation

§

Planet

§

Star

§

Galaxy

§

UkCountyCode

§

UkPostcodeArea

§

UkCounty

§

UkCity

§

UkRoadType

§

UkRiver

§

UkStreet

§

UsStateAbbr

§

UsState

§

UsRoad

§

UsRoadType

§

Word

§

Job

§

CompanyName

§

ItCompanyName

§

EnergyCompanyName

§

FinanceCompanyName

§

RetailCompanyName

§

FoodCompanyName

§

TravelCompanyName

§

ConstructionCompanyName

§

MediaCompanyName

§

TelecomCompanyName

§

BioCompanyName

§

CarBrand

§

AirDefenseCompanyName

§

ClothingCompanyName

§

Country

§

City

§

Continent

§

CountryCode

§

Street

§

River

Implementations§

Source§

impl DataType

Source

pub const fn list() -> &'static [Self]

List of all the available data types.

§Examples
use random_data::*;

#[cfg(feature = "computer")]
assert!(DataType::list().contains(&DataType::DirPath));
Source

pub const fn list_str() -> &'static [&'static str]

List of all the available data types, in string format.

§Examples
use random_data::*;

#[cfg(feature = "sky_space")]
assert!(DataType::list_str().contains(&"TypesOfCloud"));
Source§

impl DataType

Source

pub fn random(&self, generator: &mut DataGenerator) -> String

Generate a random value of the according DataType

§Examples
use random_data::*;
let mut generator = DataGenerator::new();

#[cfg(feature = "science")]
{
    let random_address = DataType::ChemicalElement.random(&mut generator);
    println!("{random_address}");
}
Source

pub const fn values(&self) -> Option<&'static [&'static str]>

Returns the list of possible values of a data type if applicable

§Returns
  • Some if the data type is defined by a list of values
  • None if it is generated from a formula
§Examples
use random_data::*;
let mut generator = DataGenerator::new();

#[cfg(feature = "people")]
{
    let mathematician = DataType::Mathematician.random(&mut generator);
    let mathematicians = DataType::Mathematician.values().unwrap();
    assert!(mathematicians.contains(&mathematician.as_ref()));
}

#[cfg(feature = "personal")]
assert!(DataType::Email.values().is_none());

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> DataType

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DataType

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for DataType

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for DataType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DataType

Source§

fn eq(&self, other: &DataType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&String> for DataType

Source§

type Error = ()

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

fn try_from(value: &String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for DataType

Source§

type Error = ()

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

fn try_from(value: &str) -> Result<Self, ()>

Performs the conversion.
Source§

impl Copy for DataType

Source§

impl Eq for DataType

Source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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