Struct petname::Petnames

source ·
pub struct Petnames<'a> {
    pub adjectives: Words<'a>,
    pub adverbs: Words<'a>,
    pub nouns: Words<'a>,
}
Expand description

Word lists and the logic to combine them into petnames.

A petname with n words will contain, in order:

  • n - 2 adverbs when n >= 2, otherwise 0 adverbs.
  • 1 adjective when n >= 2, otherwise 0 adjectives.
  • 1 noun when n >= 1, otherwise 0 nouns.

Fields§

§adjectives: Words<'a>§adverbs: Words<'a>§nouns: Words<'a>

Implementations§

source§

impl<'a> Petnames<'a>

source

pub fn small() -> Self

Constructs a new Petnames from the small word lists.

source

pub fn medium() -> Self

Constructs a new Petnames from the medium word lists.

source

pub fn large() -> Self

Constructs a new Petnames from the large word lists.

source

pub fn new(adjectives: &'a str, adverbs: &'a str, nouns: &'a str) -> Self

Constructs a new Petnames from the given word lists.

The words are extracted from the given strings by splitting on whitespace.

source

pub fn retain<F>(&mut self, predicate: F)
where F: FnMut(&str) -> bool,

Keep words matching a predicate.

§Examples
let mut petnames = petname::Petnames::default();
petnames.retain(|s| s.starts_with("h"));
assert!(petnames.generate_one(2, ".").unwrap().starts_with('h'));

This is a convenience wrapper that applies the same predicate to the adjectives, adverbs, and nouns lists.

source

pub fn cardinality(&self, words: u8) -> u128

Calculate the cardinality of this Petnames.

If this is low, names may be repeated by the generator with a higher frequency than your use-case may allow.

This can saturate. If the total possible combinations of words exceeds u128::MAX then this will return u128::MAX.

Trait Implementations§

source§

impl<'a> Clone for Petnames<'a>

source§

fn clone(&self) -> Petnames<'a>

Returns a copy 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<'a> Debug for Petnames<'a>

source§

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

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

impl<'a> Default for Petnames<'a>

source§

fn default() -> Self

Constructs a new Petnames from the default (medium) word lists.

source§

impl<'a> From<Petnames<'a>> for Alliterations<'a>

source§

fn from(petnames: Petnames<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> Generator<'a> for Petnames<'a>

source§

fn generate( &self, rng: &mut dyn RngCore, words: u8, separator: &str ) -> Option<String>

Generate a new petname. Read more
source§

fn generate_one(&self, words: u8, separator: &str) -> Option<String>

Generate a single new petname. Read more
source§

fn iter( &'a self, rng: &'a mut dyn RngCore, words: u8, separator: &str ) -> Box<dyn Iterator<Item = String> + 'a>
where Self: Sized,

Iterator yielding petnames. Read more
source§

impl<'a> PartialEq for Petnames<'a>

source§

fn eq(&self, other: &Petnames<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Petnames<'a>

source§

impl<'a> StructuralPartialEq for Petnames<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Petnames<'a>

§

impl<'a> RefUnwindSafe for Petnames<'a>

§

impl<'a> Send for Petnames<'a>

§

impl<'a> Sync for Petnames<'a>

§

impl<'a> Unpin for Petnames<'a>

§

impl<'a> UnwindSafe for Petnames<'a>

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

§

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>,

§

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>,

§

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