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 whenn >= 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>
impl<'a> Petnames<'a>
sourcepub fn new(adjectives: &'a str, adverbs: &'a str, nouns: &'a str) -> Self
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.
sourcepub fn retain<F>(&mut self, predicate: F)
pub fn retain<F>(&mut self, predicate: F)
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.
sourcepub fn cardinality(&self, words: u8) -> u128
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> From<Petnames<'a>> for Alliterations<'a>
impl<'a> From<Petnames<'a>> for Alliterations<'a>
source§impl<'a> Generator<'a> for Petnames<'a>
impl<'a> Generator<'a> for Petnames<'a>
source§impl<'a> PartialEq for Petnames<'a>
impl<'a> PartialEq for Petnames<'a>
impl<'a> Eq for Petnames<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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