use core::fmt;
use crate::{
generator::{Poll, Result},
id::SnowflakeId,
time::TimeSource,
};
pub trait SnowflakeGenerator<ID, T>
where
ID: SnowflakeId,
T: TimeSource<ID::Ty>,
{
type Err: fmt::Debug;
fn new(machine_id: ID::Ty, time: T) -> Self;
fn next_id(&self, f: impl FnMut(ID::Ty)) -> ID
where
Self::Err: Into<core::convert::Infallible>,
{
match self.try_next_id(f) {
Ok(id) => id,
Err(e) => {
#[allow(unreachable_code)]
match e.into() {}
}
}
}
fn try_next_id(&self, f: impl FnMut(ID::Ty)) -> Result<ID, Self::Err>;
fn poll_id(&self) -> Poll<ID>
where
Self::Err: Into<core::convert::Infallible>,
{
match self.try_poll_id() {
Ok(status) => status,
Err(e) => {
#[allow(unreachable_code)]
match e.into() {}
}
}
}
fn try_poll_id(&self) -> Result<Poll<ID>, Self::Err>;
}