[−][src]Struct ulid::Generator
A Ulid generator that provides monotonically increasing Ulids
Implementations
impl Generator
[src]
pub fn new() -> Generator
[src]
Create a new ulid generator for monotonically ordered ulids
Example
use ulid::Generator; let mut gen = Generator::new(); let ulid1 = gen.generate().unwrap(); let ulid2 = gen.generate().unwrap(); assert!(ulid1 < ulid2);
pub fn generate(&mut self) -> Result<Ulid, MonotonicError>
[src]
Generate a new Ulid. Each call is guaranteed to provide a Ulid with a larger value than the last call. If the random bits would overflow, this method will return an error.
use ulid::Generator; let mut gen = Generator::new(); let ulid1 = gen.generate().unwrap(); let ulid2 = gen.generate().unwrap(); assert!(ulid1 < ulid2);
pub fn generate_from_datetime<T: TimeZone>(
&mut self,
datetime: DateTime<T>
) -> Result<Ulid, MonotonicError>
[src]
&mut self,
datetime: DateTime<T>
) -> Result<Ulid, MonotonicError>
Generate a new Ulid matching the given DateTime. Each call is guaranteed to provide a Ulid with a larger value than the last call. If the random bits would overflow, this method will return an error.
Example
use ulid::Generator; use chrono::Utc; let dt = Utc::now(); let mut gen = Generator::new(); let ulid1 = gen.generate_from_datetime(dt).unwrap(); let ulid2 = gen.generate_from_datetime(dt).unwrap(); assert_eq!(ulid1.datetime(), ulid2.datetime()); assert!(ulid1 < ulid2);
pub fn generate_with_source<R>(
&mut self,
source: &mut R
) -> Result<Ulid, MonotonicError> where
R: Rng,
[src]
&mut self,
source: &mut R
) -> Result<Ulid, MonotonicError> where
R: Rng,
Generate a new monotonic increasing Ulid with the given source Each call is guaranteed to provide a Ulid with a larger value than the last call. If the random bits would overflow, this method will return an error.
Example
use ulid::Generator; use ulid::Ulid; use chrono::Utc; use rand::FromEntropy; use rand::rngs::SmallRng; let mut rng = SmallRng::from_entropy(); let mut gen = Generator::new(); let ulid1 = gen.generate_with_source(&mut rng).unwrap(); let ulid2 = gen.generate_with_source(&mut rng).unwrap(); assert!(ulid1 < ulid2);
pub fn generate_from_datetime_with_source<T, R>(
&mut self,
datetime: DateTime<T>,
source: &mut R
) -> Result<Ulid, MonotonicError> where
T: TimeZone,
R: Rng,
[src]
&mut self,
datetime: DateTime<T>,
source: &mut R
) -> Result<Ulid, MonotonicError> where
T: TimeZone,
R: Rng,
Generate a new monotonic increasing Ulid with the given source matching the given DateTime Each call is guaranteed to provide a Ulid with a larger value than the last call. If the random bits would overflow, this method will return an error.
Example
use ulid::Generator; use chrono::Utc; use rand::FromEntropy; use rand::rngs::SmallRng; let dt = Utc::now(); let mut rng = SmallRng::from_entropy(); let mut gen = Generator::new(); let ulid1 = gen.generate_from_datetime_with_source(dt, &mut rng).unwrap(); let ulid2 = gen.generate_from_datetime_with_source(dt, &mut rng).unwrap(); assert_eq!(ulid1.datetime(), ulid2.datetime()); assert!(ulid1 < ulid2);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Generator
impl Send for Generator
impl Sync for Generator
impl Unpin for Generator
impl UnwindSafe for Generator
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>,