Skip to main content

CodeBuilder

Struct CodeBuilder 

Source
pub struct CodeBuilder<R: RandomSource> { /* private fields */ }
Expand description

Chainable string composer. It only joins string fragments; it has no uniqueness, retry, persistence, or denylist policy.

Implementations§

Source§

impl<R: RandomSource> CodeBuilder<R>

Source

pub fn new(rng: R) -> Self

Start a builder with the given random source.

Source

pub fn add(self, value: impl Into<String>) -> Self

Append an arbitrary string fragment.

Source

pub fn add_with<F: FnOnce(&mut R) -> String>(self, f: F) -> Self

Append a fragment produced from the builder’s own random source.

Language crates use this to add generated words without owning a second random source.

Source

pub fn dash(self) -> Self

Append a - separator.

Source

pub fn digits(self, length: usize) -> Self

Append length random decimal digits.

Source

pub fn nums(self, length: usize) -> Self

Source

pub fn build(self) -> String

Finalize and return the joined code string.

Auto Trait Implementations§

§

impl<R> Freeze for CodeBuilder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for CodeBuilder<R>
where R: RefUnwindSafe,

§

impl<R> Send for CodeBuilder<R>
where R: Send,

§

impl<R> Sync for CodeBuilder<R>
where R: Sync,

§

impl<R> Unpin for CodeBuilder<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for CodeBuilder<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for CodeBuilder<R>
where R: UnwindSafe,

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