nurtex_protocol/types/
face.rs1use std::io::{self, Cursor, Write};
2
3use nurtex_codec::Buffer;
4
5#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
7pub enum Face {
8 Bottom,
9 Top,
10 North,
11 South,
12 West,
13 East,
14}
15
16impl Buffer for Face {
17 fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
18 let id = i8::read_buf(buffer)?;
19
20 Some(match id {
21 0 => Self::Bottom,
22 1 => Self::Top,
23 2 => Self::North,
24 3 => Self::South,
25 4 => Self::West,
26 5 => Self::East,
27 _ => return None,
28 })
29 }
30
31 fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
32 let id = match self {
33 Self::Bottom => 0,
34 Self::Top => 1,
35 Self::North => 2,
36 Self::South => 3,
37 Self::West => 4,
38 Self::East => 5,
39 };
40
41 (id as i8).write_buf(buffer)?;
42
43 Ok(())
44 }
45}