File_system/Fundamentals/
Size.rsuse core::{
fmt::{self, Display, Formatter},
ops::{Add, AddAssign},
};
#[derive(Default, PartialOrd, PartialEq, Eq, Ord, Clone, Copy, Debug)]
#[repr(transparent)]
pub struct Size_type(u64);
impl Display for Size_type {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl Size_type {
pub const fn New(Item: u64) -> Self {
Size_type(Item)
}
pub const fn As_u64(&self) -> u64 {
self.0
}
}
impl PartialEq<usize> for Size_type {
fn eq(&self, other: &usize) -> bool {
self.0 == *other as u64
}
}
impl From<usize> for Size_type {
fn from(item: usize) -> Self {
Size_type(item as u64)
}
}
impl From<u64> for Size_type {
fn from(item: u64) -> Self {
Size_type(item)
}
}
impl From<Size_type> for usize {
fn from(item: Size_type) -> Self {
item.0 as usize
}
}
impl From<Size_type> for u64 {
fn from(item: Size_type) -> Self {
item.0
}
}
impl Add<Size_type> for Size_type {
type Output = Size_type;
fn add(self, rhs: Size_type) -> Self::Output {
Size_type(self.0 + rhs.0)
}
}
impl Add<usize> for Size_type {
type Output = Size_type;
fn add(self, rhs: usize) -> Self::Output {
Size_type(self.0 + rhs as u64)
}
}
impl Add<u64> for Size_type {
type Output = Size_type;
fn add(self, rhs: u64) -> Self::Output {
Size_type(self.0 + rhs)
}
}
impl Add<Size_type> for usize {
type Output = Size_type;
fn add(self, rhs: Size_type) -> Self::Output {
Size_type(self as u64 + rhs.0)
}
}
impl Add<Size_type> for u64 {
type Output = Size_type;
fn add(self, rhs: Size_type) -> Self::Output {
Size_type(self + rhs.0)
}
}
impl AddAssign<Size_type> for Size_type {
fn add_assign(&mut self, rhs: Size_type) {
self.0 += rhs.0;
}
}
impl AddAssign<usize> for Size_type {
fn add_assign(&mut self, rhs: usize) {
self.0 += rhs as u64;
}
}
impl AddAssign<u64> for Size_type {
fn add_assign(&mut self, rhs: u64) {
self.0 += rhs;
}
}
impl AddAssign<Size_type> for usize {
fn add_assign(&mut self, rhs: Size_type) {
*self += rhs.0 as usize;
}
}