Skip to main content

nurtex_codec/types/basic/
boolean.rs

1use crate::Buffer;
2
3impl Buffer for bool {
4  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
5    let byte = u8::read_buf(buffer)?;
6
7    if byte > 1 {
8      return None;
9    }
10
11    Some(byte != 0)
12  }
13
14  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
15    let byte = u8::from(*self);
16    byte.write_buf(buffer)
17  }
18}