use std::{fmt::{Debug, Display},
ops::Deref};
#[derive(Default, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FlexBoxId {
pub inner: u8,
}
impl FlexBoxId {
pub fn new(arg_id: impl Into<u8>) -> Self {
Self {
inner: arg_id.into(),
}
}
}
impl From<FlexBoxId> for u8 {
fn from(id: FlexBoxId) -> Self { id.inner }
}
impl From<u8> for FlexBoxId {
fn from(id: u8) -> Self { Self { inner: id } }
}
impl Deref for FlexBoxId {
type Target = u8;
fn deref(&self) -> &Self::Target { &self.inner }
}
impl Debug for FlexBoxId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "❬{}❭", self.inner)
}
}
impl Display for FlexBoxId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_flex_box_id_default() {
let id = FlexBoxId::default();
assert_eq!(id.inner, 0);
}
#[test]
fn test_flex_box_id_from_u8() {
let id = FlexBoxId::from(42u8);
assert_eq!(id.inner, 42);
}
#[test]
fn test_u8_from_flex_box_id() {
let id = FlexBoxId::new(42);
let value: u8 = id.into();
assert_eq!(value, 42);
}
#[test]
fn test_flex_box_id_deref() {
let id = FlexBoxId::new(42);
assert_eq!(*id, 42);
}
#[test]
fn test_flex_box_id_debug() {
let id = FlexBoxId::new(42);
assert_eq!(format!("{id:?}"), "❬42❭");
}
#[test]
fn test_flex_box_id_display() {
let id = FlexBoxId::new(42);
assert_eq!(format!("{id:?}"), "❬42❭");
}
}