djin_protocol/types/
char.rs1use crate::{hint, Parcel, Error, CharTryFromError, Settings};
2use std::char;
3use std::io::prelude::*;
4
5impl Parcel for char
6{
7 const TYPE_NAME: &'static str = "char";
8
9 fn read_field(read: &mut dyn Read,
10 settings: &Settings,
11 _: &mut hint::Hints) -> Result<Self, Error> {
12 let bytes = u32::read(read, settings)?;
13 Ok(char::from_u32(bytes).ok_or(CharTryFromError{ })?)
14 }
15
16 fn write_field(&self, write: &mut dyn Write,
17 settings: &Settings,
18 _: &mut hint::Hints) -> Result<(), Error> {
19 (*self as u32).write(write, settings)
20 }
21}
22