#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct CredentialGeneration(u64);
impl CredentialGeneration {
pub const INITIAL: Self = Self(1);
#[must_use]
pub const fn get(self) -> u64 {
self.0
}
#[must_use]
pub const fn refresh_handoff(self) -> RefreshHandoff {
RefreshHandoff { expected: self }
}
pub fn checked_next(self) -> Result<Self, CredentialGenerationError> {
self.0
.checked_add(1)
.map(Self)
.ok_or(CredentialGenerationError::Exhausted)
}
#[cfg(test)]
pub(super) const fn from_raw_for_test(value: u64) -> Self {
Self(value)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct RefreshHandoff {
expected: CredentialGeneration,
}
impl RefreshHandoff {
#[must_use]
pub const fn expected_generation(self) -> CredentialGeneration {
self.expected
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CredentialGenerationError {
Exhausted,
}
impl_static_error!(CredentialGenerationError,
Self::Exhausted => "credential generation is exhausted",
);