wubi 0.2.0

Self-developed Wubi 86 encoder, dictionary, and dataset (PHF + FST, WASM-ready).
Documentation
//! 字根 → letter lookup, backed by a compile-time `phf::Map<char, u8>`
//! generated by `build.rs` from `data/zigen86.txt`.

include!(concat!(env!("OUT_DIR"), "/zigen.phf.rs"));

/// Look up the key letter (lowercase ASCII) for a 字根.
///
/// Compiles to a perfect-hash probe with no allocation, no synchronization.
#[inline]
pub fn lookup(zigen: char) -> Option<u8> {
    ZIGEN.get(&zigen).copied()
}

/// Iterate all (字根, key letter) pairs in the embedded table.
/// Order is unspecified (PHF internal).
pub fn iter() -> impl Iterator<Item = (char, u8)> + 'static {
    ZIGEN.entries().map(|(k, v)| (*k, *v))
}

#[doc(hidden)]
pub fn entries_for_test() -> usize {
    ZIGEN.len()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parses_canonical_25_plus_extras() {
        assert!(entries_for_test() >= 25);
        assert_eq!(lookup(''), Some(b'g'));
        assert_eq!(lookup(''), Some(b'f'));
        assert_eq!(lookup(''), Some(b'd'));
        assert_eq!(lookup(''), Some(b'x'));
        assert_eq!(lookup(''), Some(b'o'));
        assert_eq!(lookup(''), Some(b'g'));
        assert_eq!(lookup(''), Some(b'h'));
        assert_eq!(lookup('丿'), Some(b't'));
        assert_eq!(lookup(''), Some(b'y'));
        assert_eq!(lookup(''), Some(b'n'));
    }

    #[test]
    fn unknown_returns_none() {
        assert_eq!(lookup('Z'), None);
        assert_eq!(lookup('🍌'), None);
    }
}