use core::fmt;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ResourceVector {
pub entries: u64,
pub bytes: u64,
}
impl ResourceVector {
#[must_use]
pub const fn new(entries: u64, bytes: u64) -> Self {
Self { entries, bytes }
}
#[must_use]
pub const fn widen(self) -> WideResourceVector {
WideResourceVector::new(widen_u64(self.entries), widen_u64(self.bytes))
}
}
#[allow(clippy::cast_lossless)]
pub(super) const fn widen_u64(value: u64) -> u128 {
value as u128
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct WideResourceVector {
pub entries: u128,
pub bytes: u128,
}
impl WideResourceVector {
#[must_use]
pub const fn new(entries: u128, bytes: u128) -> Self {
Self { entries, bytes }
}
#[must_use]
pub const fn is_zero(self) -> bool {
self.entries == 0 && self.bytes == 0
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ResourceDimension {
Entries,
Bytes,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BaselineError {
MarkerCreditsExceedIdentitySlots {
identity_slots: u64,
marker_credits: u64,
},
}
impl fmt::Display for BaselineError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MarkerCreditsExceedIdentitySlots {
identity_slots,
marker_credits,
} => write!(
formatter,
"marker credits ({marker_credits}) exceed identity slots ({identity_slots})"
),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct MandatoryCapacity {
pub debt: WideResourceVector,
pub absolute_fit: bool,
pub debt_within_mandatory_bound: bool,
}
impl MandatoryCapacity {
#[must_use]
pub const fn is_legal(self) -> bool {
self.absolute_fit && self.debt_within_mandatory_bound
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RecoveryTransfer {
pub baseline: WideResourceVector,
pub remaining_recovery_claim: ResourceVector,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RecoveryTransferError {
pub dimension: ResourceDimension,
}
impl fmt::Display for RecoveryTransferError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"recovery charge exceeds remaining {:?} claim",
self.dimension
)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FloorComputation {
pub member_cursor: u64,
pub preferred_floor: u128,
pub resulting_floor: u128,
}