Cuid2Constructor

Struct Cuid2Constructor 

Source
pub struct Cuid2Constructor { /* private fields */ }
Expand description

Provides customization of CUID generation.

use cuid2::CuidConstructor;

let mut constructor = CuidConstructor::new();
assert_eq!(24, constructor.create_id().len());

constructor.set_length(16);
assert_eq!(16, constructor.create_id().len());

assert_eq!(32, CuidConstructor::new().with_length(32).create_id().len());

Implementations§

Source§

impl CuidConstructor

Source

pub const fn new() -> CuidConstructor

Creates a new constructor with default settings.

Source

pub const fn with_length(self, length: u16) -> CuidConstructor

Returns a new constructor that will generate CUIDs with the specified length.

§Panics

Panics if length is less than 2.

Source

pub const fn with_counter(self, counter: fn() -> u64) -> CuidConstructor

Returns a new constructor with the specified counter function.

Source

pub const fn with_fingerprinter( self, fingerprinter: fn() -> String, ) -> CuidConstructor

Returns a new constructor with the specified fingerprinter function.

Source

pub fn set_length(&mut self, length: u16)

Sets the length for CUIDs generated by this constrctor.

§Panics

Panics if length is less than 2.

Source

pub fn set_counter(&mut self, counter: fn() -> u64)

Sets the counter function for this constructor.

Source

pub fn set_fingerprinter(&mut self, fingerprinter: fn() -> String)

Sets the fingerperinter function for this constructor.

Source

pub fn create_id(&self) -> String

Creates a new CUID.

Trait Implementations§

Source§

impl Default for CuidConstructor

Source§

fn default() -> CuidConstructor

Returns the “default value” for a type. Read more

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> 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> Same for T

Source§

type Output = T

Should always be Self
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