use std::time::{SystemTime, UNIX_EPOCH};
use crate::{const_panic_new, INSTANCE_MAX};
#[derive(Copy, Clone, Debug)]
pub struct Builder {
pub(crate) instance: u16,
pub(crate) epoch: SystemTime,
}
impl Builder {
#[inline]
pub const fn new() -> Self {
Self {
instance: 0,
epoch: UNIX_EPOCH,
}
}
#[inline]
pub const fn instance(self, instance: u16) -> Self {
match self.instance_checked(instance) {
Some(this) => this,
None => const_panic_new(),
}
}
#[inline]
pub const fn instance_checked(mut self, instance: u16) -> Option<Self> {
if instance > INSTANCE_MAX {
None
} else {
self.instance = instance;
Some(self)
}
}
#[inline]
pub const fn instance_unchecked(mut self, instance: u16) -> Self {
self.instance = instance;
self
}
#[inline]
pub const fn epoch(mut self, epoch: SystemTime) -> Self {
self.epoch = epoch;
self
}
#[inline]
pub fn build<T>(self) -> T
where
T: From<Self>,
{
T::from(self)
}
}