1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct ChunkId(pub [u8; 4]);
6
7impl ChunkId {
8 pub const fn new(array: [u8; 4]) -> Self {
10 Self(array)
11 }
12
13 pub const fn from_str(s: &str) -> Self {
19 assert!(s.len() == 4, "ChunkId must be exactly 4 bytes");
20 let bytes = s.as_bytes();
21 Self([bytes[0], bytes[1], bytes[2], bytes[3]])
22 }
23
24 pub fn as_bytes(&self) -> &[u8; 4] {
26 &self.0
27 }
28}
29
30impl fmt::Display for ChunkId {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 if self.0.iter().all(|&b| b.is_ascii_graphic()) {
34 write!(f, "{}", std::str::from_utf8(&self.0).unwrap_or("????"))
35 } else {
36 write!(
37 f,
38 "0x{:02X}{:02X}{:02X}{:02X}",
39 self.0[0], self.0[1], self.0[2], self.0[3]
40 )
41 }
42 }
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Default)]
47pub struct Vec3 {
48 pub x: f32,
49 pub y: f32,
50 pub z: f32,
51}
52
53#[derive(Debug, Clone, Copy, PartialEq)]
55pub struct BoundingBox {
56 pub min: Vec3,
57 pub max: Vec3,
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
62pub struct Color {
63 pub r: u8,
64 pub g: u8,
65 pub b: u8,
66 pub a: u8,
67}