pub(crate) struct Layer {
pub(crate) root: &'static str,
suffixes: fst::Set<&'static [u8]>,
names: fst::Set<&'static [u8]>,
}
impl Layer {
fn new(root: &'static str, suffixes: &'static [u8], names: &'static [u8]) -> Self {
let set = |bytes| fst::Set::new(bytes).expect("data/std holds fst sets written by xtask");
Self {
root,
suffixes: set(suffixes),
names: set(names),
}
}
pub(crate) fn ends_a_path(&self, path: &str) -> bool {
self.suffixes.contains(path)
}
pub(crate) fn has_name(&self, name: &str) -> bool {
self.names.contains(name)
}
}
pub(crate) fn layers() -> [Layer; 4] {
[
Layer::new(
"core",
include_bytes!("../data/std/core.fst"),
include_bytes!("../data/std/core-names.fst"),
),
Layer::new(
"alloc",
include_bytes!("../data/std/alloc.fst"),
include_bytes!("../data/std/alloc-names.fst"),
),
Layer::new(
"std",
include_bytes!("../data/std/std.fst"),
include_bytes!("../data/std/std-names.fst"),
),
Layer::new(
"proc_macro",
include_bytes!("../data/std/proc_macro.fst"),
include_bytes!("../data/std/proc_macro-names.fst"),
),
]
}
pub(crate) struct Vocabulary {
words: fst::Set<&'static [u8]>,
}
impl Vocabulary {
pub(crate) fn new() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/english/words.fst")[..])
.expect("data/english holds an fst set written by xtask"),
}
}
pub(crate) fn claims(&self, word: &str) -> bool {
self.words.contains(word.to_lowercase())
}
}