refquiem 0.1.0

A cargo requiem for the refs your Rust code left behind
Documentation
//! The standard library paths and English words that `cargo xtask vocab` builds.

/// The public paths reachable from one crate root.
pub(crate) struct Layer {
    /// The root the layer's paths start with.
    pub(crate) root: &'static str,
    /// The suffixes, of two or more segments, of every path.
    suffixes: fst::Set<&'static [u8]>,
    /// Every segment of every path.
    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),
        }
    }

    /// Whether `path`, spelled with `::`, ends a public path of this layer.
    pub(crate) fn ends_a_path(&self, path: &str) -> bool {
        self.suffixes.contains(path)
    }

    /// Whether some public path of this layer has a segment `name`.
    pub(crate) fn has_name(&self, name: &str) -> bool {
        self.names.contains(name)
    }
}

/// The `core`, `alloc`, `std` and `proc_macro` layers.
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"),
        ),
    ]
}

/// English words, hyphenated compounds included, which a bare name in running text may
/// simply be.
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"),
        }
    }

    /// Whether `word`, case-folded, is an English word.
    pub(crate) fn claims(&self, word: &str) -> bool {
        self.words.contains(word.to_lowercase())
    }
}