use std::num::NonZeroU64;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct LeadershipEpochV1(NonZeroU64);
impl LeadershipEpochV1 {
#[must_use]
pub const fn new(value: u64) -> Option<Self> {
match NonZeroU64::new(value) {
Some(value) => Some(Self(value)),
None => None,
}
}
#[must_use]
pub const fn initial() -> Self {
Self(NonZeroU64::MIN)
}
#[must_use]
pub const fn get(self) -> u64 {
self.0.get()
}
#[must_use]
pub const fn checked_next(self) -> Option<Self> {
match self.get().checked_add(1) {
Some(next) => Self::new(next),
None => None,
}
}
}
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ReplicationSourceHoldIdV1([u8; 16]);
impl ReplicationSourceHoldIdV1 {
#[must_use]
pub fn new(bytes: [u8; 16]) -> Option<Self> {
(bytes != [0; 16]).then_some(Self(bytes))
}
#[must_use]
pub const fn as_bytes(&self) -> &[u8; 16] {
&self.0
}
}
impl std::fmt::Debug for ReplicationSourceHoldIdV1 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ReplicationSourceHoldIdV1([redacted])")
}
}
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct ReplicationFollowerAuditTargetV1 {
database_id: crate::DatabaseId,
history_incarnation: NonZeroU64,
leadership_epoch: LeadershipEpochV1,
hold_id: ReplicationSourceHoldIdV1,
}
impl ReplicationFollowerAuditTargetV1 {
#[must_use]
pub const fn new(
database_id: crate::DatabaseId,
history_incarnation: u64,
leadership_epoch: LeadershipEpochV1,
hold_id: ReplicationSourceHoldIdV1,
) -> Option<Self> {
match NonZeroU64::new(history_incarnation) {
Some(history_incarnation) => Some(Self {
database_id,
history_incarnation,
leadership_epoch,
hold_id,
}),
None => None,
}
}
#[must_use]
pub const fn database_id(self) -> crate::DatabaseId {
self.database_id
}
#[must_use]
pub const fn history_incarnation(self) -> u64 {
self.history_incarnation.get()
}
#[must_use]
pub const fn leadership_epoch(self) -> LeadershipEpochV1 {
self.leadership_epoch
}
#[must_use]
pub const fn hold_id(self) -> ReplicationSourceHoldIdV1 {
self.hold_id
}
}
impl std::fmt::Debug for ReplicationFollowerAuditTargetV1 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ReplicationFollowerAuditTargetV1([REDACTED])")
}
}