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 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.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Generator
impl UnwindSafe for Generator