pub enum Error {
IdSegInvalid,
EpochInvalid,
SequenceInvalid,
TimestampMaxReached,
SequenceMaxReached(Duration),
TimestampError,
MutexError,
InvalidId,
TooManySegments,
}Expand description
possible errors for Snowclouds/Snowflakes
since the errors are not very complex no additional information is provided except for SequenceMaxReached that provides the duration to the next millisecond.
this error implements NextAvailId if being
used in a generic way.
use snowcloud::Error::SequenceMaxReached;
type MyFlake = snowcloud::i64::SingleIdFlake<43, 8, 12>;
type MyCloud = snowcloud::Generator<MyFlake>;
const START_TIME: u64 = 1679587200000;
let mut cloud = MyCloud::new(START_TIME, 1)
.expect("failed to create MyCloud");
match cloud.next_id() {
Ok(flake) => {
println!("{}", flake.id());
},
Err(err) => {
match err {
SequenceMaxReached(dur) => {
// we can wait for the specified duration to try again
},
_ => {
println!("{}", err);
}
}
}
}Variants§
IdSegInvalid
a provided id seg is invalid.
EpochInvalid
a provided epoch is invalid
SequenceInvalid
a provided sequence is less than 0 or greater than the max value specified by a Snowflake
TimestampMaxReached
the max possible timestamp value has been reached when generating a new id
SequenceMaxReached(Duration)
the max possible sequence value has been reached when generating a new id. the returned duration is an estimate on how long to wait for the next millisecond
TimestampError
failed to get a valid UNIX EPOCH timestamp
MutexError
error when attempting to lock a mutex
InvalidId
the provided i64 is not a valid Snowflake
TooManySegments
provided too many segments for creating a Snowflake