Struct beryl::generator::Generator[][src]

pub struct Generator {
    pub id: u16,
    pub epoch: SystemTime,
    // some fields omitted
}
Expand description

Generates Crystals

Fields

id: u16

The unique ID of this generator within the Beryl scope

epoch: SystemTime

The epoch which timestamps are measured from

Implementations

Construct a new generator with the given ID and Epoch

Generate a Crystal using the recommended blocking method, spinning until the millisecond is over. This may not be the best method for your use case. You should run your own benchmarks if Generator speed is a consideration.

Example

use std::time::SystemTime;

let mut gen = Generator::new(0, SystemTime::UNIX_EPOCH)?;

// Generate a few snowflakes
for _ in 0..2 {
    println!("{:?}", gen.generate());
}

Try to generate a Crystal, returning BerylError::GeneratorExhausted if the Generator has exhausted the set of Crystals which can be generated in that millisecond.

Generate a Crystal, checking the time every 100ns when the counter is saturated. This wastes a little time if the system has a high-precision sleep call, and a lot if it doesn’t. You should do your own testing if Generator speed is a consideration.

Generate a Crystal, checking the time constantly until the next millisecond when the counter is saturated. This generates many syscalls; however, for use cases where the entire program must block on the generator or on systems which lack high-precision sleep calls, it may be the best option. You should do your own testing if Generator speed is a consideration.

Generate a Crystal without checking to make sure that Crystal hasn’t been generated before.

Warning

Do not use this unless you know what you are doing. If you aren’t absolutely sure you’ll produce less than 1024 Crystals/ms, this will create conflicting Crystals.

Trait Implementations

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.