The crate bytes
doesn't provide anyway to reset position to 0, so I'm stuck with this inefficient code:
static BASIC_PLANE: &'static [u8] = include_bytes!("./general_category_data/basic.bin");
impl From<char> for GeneralCategory {
fn from(code_point: char) -> Self {
let code_point = code_point as usize;
let mut compare_code_point: usize = 0;
let mut count: usize = 0;
let mut category_value: u8 = 0;
if code_point < 0x10000 {
let plane = Bytes::from_static(BASIC_PLANE);
...
}
...
}
}
The problem is that GeneralCategory::from
will be called frequently, and I believe the line Bytes::from_static(BASIC_PLANE);
will clone the bytes contents on the fly. I wanted to rather store Bytes
as a static
variable, but as I said there's no set_position
method. Someone on Discord said the byteorder
crate could be better suited for my needs, but then it requires me to convert the static &'static [u8]
into Vec<u8>
(that's what Cursor::new
accepts).