ctoolbox/formats/eite/encoding/
ascii.rs

1use anyhow::{Result, ensure};
2
3pub fn byte_from_stagel_char(s: &str) -> Result<u8> {
4    let c = s.chars().next().expect("empty string for byte_from_char");
5    let code = u32::from(c);
6    ensure!((32..127).contains(&code), "Non-ASCII supported range");
7    Ok(u8::try_from(code).expect("Failed to convert code to u8"))
8}
9
10pub fn stagel_char_from_byte(b: u8) -> Result<String> {
11    ensure!((0x20..=0x7E).contains(&b), "Out of visible ASCII range");
12    Ok((char::from(b)).to_string())
13}