diff options
Diffstat (limited to 'evc/src/vec2.rs')
-rw-r--r-- | evc/src/vec2.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/evc/src/vec2.rs b/evc/src/vec2.rs index b1dd1b4..8b01fdb 100644 --- a/evc/src/vec2.rs +++ b/evc/src/vec2.rs @@ -26,6 +26,21 @@ impl Ser for Vec2 { } } +pub struct Small<T>(pub T); +impl Ser for Small<Vec2> { + fn write(&self, sink: &mut impl std::io::Write) -> anyhow::Result<()> { + sink.put((self.0.x as i8, self.0.y as i8)) + } + + fn read(source: &mut impl std::io::Read) -> anyhow::Result<Self> { + let (x, y): (i8, i8) = source.get()?; + Ok(Small(Vec2 { + x: x as isize, + y: y as isize, + })) + } +} + impl std::ops::Add for Vec2 { type Output = Vec2; #[inline] |