Skip to main content

steel_utils/codec/
glam.rs

1use crate::serial::{ReadFrom, WriteTo};
2use glam::{DVec3, IVec2, IVec3, Vec3};
3use std::io::{Cursor, Result, Write};
4
5impl WriteTo for IVec2 {
6    fn write(&self, writer: &mut impl Write) -> Result<()> {
7        self.x.write(writer)?;
8        self.y.write(writer)
9    }
10}
11
12impl ReadFrom for IVec2 {
13    fn read(data: &mut Cursor<&[u8]>) -> Result<Self> {
14        Ok(Self {
15            x: i32::read(data)?,
16            y: i32::read(data)?,
17        })
18    }
19}
20
21impl WriteTo for IVec3 {
22    fn write(&self, writer: &mut impl Write) -> Result<()> {
23        self.x.write(writer)?;
24        self.y.write(writer)?;
25        self.z.write(writer)
26    }
27}
28
29impl ReadFrom for IVec3 {
30    fn read(data: &mut Cursor<&[u8]>) -> Result<Self> {
31        Ok(Self {
32            x: i32::read(data)?,
33            y: i32::read(data)?,
34            z: i32::read(data)?,
35        })
36    }
37}
38
39impl WriteTo for DVec3 {
40    fn write(&self, writer: &mut impl Write) -> Result<()> {
41        self.x.write(writer)?;
42        self.y.write(writer)?;
43        self.z.write(writer)
44    }
45}
46
47impl ReadFrom for DVec3 {
48    fn read(data: &mut Cursor<&[u8]>) -> Result<Self> {
49        Ok(Self {
50            x: f64::read(data)?,
51            y: f64::read(data)?,
52            z: f64::read(data)?,
53        })
54    }
55}
56
57impl WriteTo for Vec3 {
58    fn write(&self, writer: &mut impl Write) -> Result<()> {
59        self.x.write(writer)?;
60        self.y.write(writer)?;
61        self.z.write(writer)
62    }
63}
64
65impl ReadFrom for Vec3 {
66    fn read(data: &mut Cursor<&[u8]>) -> Result<Self> {
67        Ok(Self {
68            x: f32::read(data)?,
69            y: f32::read(data)?,
70            z: f32::read(data)?,
71        })
72    }
73}