#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum SegmentRole {
Core = 0,
Extension = 1,
Journal = 2,
Index = 3,
Cache = 4,
Audit = 5,
Shard = 6,
Unclassified = 7,
}
impl SegmentRole {
#[inline(always)]
pub const fn from_flags(flags: u16) -> Self {
match (flags >> 12) & 0xF {
0 => Self::Core,
1 => Self::Extension,
2 => Self::Journal,
3 => Self::Index,
4 => Self::Cache,
5 => Self::Audit,
6 => Self::Shard,
_ => Self::Unclassified,
}
}
#[inline(always)]
pub const fn into_flags(self, existing_flags: u16) -> u16 {
(existing_flags & 0x0FFF) | ((self as u16) << 12)
}
#[inline(always)]
pub const fn must_preserve(&self) -> bool {
matches!(*self, Self::Core | Self::Audit)
}
#[inline(always)]
pub const fn clearable_on_migration(&self) -> bool {
matches!(*self, Self::Journal | Self::Cache)
}
#[inline(always)]
pub const fn rebuildable(&self) -> bool {
matches!(*self, Self::Index | Self::Cache)
}
#[inline(always)]
pub const fn is_append_only(&self) -> bool {
matches!(*self, Self::Journal | Self::Audit)
}
#[inline(always)]
pub const fn is_immutable_after_init(&self) -> bool {
matches!(*self, Self::Audit)
}
#[inline(always)]
pub const fn requires_migration_copy(&self) -> bool {
matches!(*self, Self::Core | Self::Audit)
}
#[inline(always)]
pub const fn is_safe_to_drop(&self) -> bool {
matches!(*self, Self::Cache)
}
#[inline(always)]
pub const fn should_emit_receipt(&self) -> bool {
matches!(
*self,
Self::Core | Self::Extension | Self::Journal | Self::Audit | Self::Shard
)
}
#[inline(always)]
pub const fn is_operator_relevant(&self) -> bool {
matches!(
*self,
Self::Core | Self::Extension | Self::Journal | Self::Audit | Self::Shard
)
}
#[inline(always)]
pub const fn may_hold_financial_state(&self) -> bool {
matches!(*self, Self::Core | Self::Extension)
}
#[inline(always)]
pub const fn name(&self) -> &'static str {
match self {
Self::Core => "core",
Self::Extension => "extension",
Self::Journal => "journal",
Self::Index => "index",
Self::Cache => "cache",
Self::Audit => "audit",
Self::Shard => "shard",
Self::Unclassified => "unclassified",
}
}
}
pub const SEG_ROLE_CORE: u16 = (SegmentRole::Core as u16) << 12;
pub const SEG_ROLE_EXTENSION: u16 = (SegmentRole::Extension as u16) << 12;
pub const SEG_ROLE_JOURNAL: u16 = (SegmentRole::Journal as u16) << 12;
pub const SEG_ROLE_INDEX: u16 = (SegmentRole::Index as u16) << 12;
pub const SEG_ROLE_CACHE: u16 = (SegmentRole::Cache as u16) << 12;
pub const SEG_ROLE_AUDIT: u16 = (SegmentRole::Audit as u16) << 12;
pub const SEG_ROLE_SHARD: u16 = (SegmentRole::Shard as u16) << 12;