use std::num::TryFromIntError;
use bincode::{Decode, Encode};
use derive_more::{Display, From};
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Encode, Decode, Display, From,
)]
#[display("{_0}")]
pub struct FragmentIndex(u32);
impl FragmentIndex {
#[must_use]
pub const fn new(value: u32) -> Self { Self(value) }
#[must_use]
pub const fn zero() -> Self { Self(0) }
#[must_use]
pub const fn get(self) -> u32 { self.0 }
#[must_use]
pub fn checked_increment(self) -> Option<Self> { self.0.checked_add(1).map(Self) }
}
impl TryFrom<usize> for FragmentIndex {
type Error = TryFromIntError;
fn try_from(value: usize) -> Result<Self, Self::Error> { u32::try_from(value).map(Self) }
}
impl From<FragmentIndex> for u32 {
fn from(value: FragmentIndex) -> Self { value.0 }
}