[−][src]Struct petname::Petnames
Word lists and the logic to combine them into petnames.
A petname with n words will contain, in order:
- 1 adjective when
n >= 2, otherwise 0 adjectives. n - 2adverbs whenn >= 2.- 1 name / noun.
Fields
adjectives: Vec<&'a str>adverbs: Vec<&'a str>names: Vec<&'a str>Methods
impl<'a> Petnames<'a>[src]
pub fn default() -> Self[src]
Constructs a new Petnames from the default (small) word lists.
pub fn small() -> Self[src]
Constructs a new Petnames from the small word lists.
pub fn medium() -> Self[src]
Constructs a new Petnames from the medium word lists.
pub fn large() -> Self[src]
Constructs a new Petnames from the large word lists.
pub fn init(adjectives: &'a str, adverbs: &'a str, names: &'a str) -> Self[src]
Constructs a new Petnames from the given word lists.
The words are extracted from the given strings by splitting on whitespace.
pub fn retain<F>(&mut self, predicate: F) where
F: Fn(&&str) -> bool, [src]
F: Fn(&&str) -> bool,
Keep words matching a predicate.
Examples
let mut petnames = petname::Petnames::default(); petnames.retain(|s| s.starts_with("b")); petnames.generate_one(2, ".");
This is merely a convenience wrapper that applies the same predicate to the adjectives, adverbs, and names lists.
pub fn cardinality(&self, words: u8) -> u128[src]
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. If it is 0 (zero) the generator
will panic (unless words is also zero).
This can saturate. If the total possible combinations of words exceeds
u128::MAX then this will return u128::MAX.
pub fn generate<RNG>(&self, rng: &mut RNG, words: u8, separator: &str) -> String where
RNG: Rng, [src]
RNG: Rng,
Generate a new petname.
Examples
let mut rng = rand::thread_rng(); petname::Petnames::default().generate(&mut rng, 7, ":");
Panics
If a word list is empty.
pub fn generate_one(&self, words: u8, separator: &str) -> String[src]
Generate a single new petname.
This is like generate but uses rand::thread_rng as the random
source. For efficiency use generate when creating multiple names, or
when you want to use a custom source of randomness.
Trait Implementations
Auto Trait Implementations
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
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,