phf_codegen 0.6.12

Codegen library for PHF types
docs.rs failed to build phf_codegen-0.6.12
Please check the build logs and, if you believe this is docs.rs' fault, open an issue.
Visit the last successful build: phf_codegen-0.8.0

A set of builders to generate Rust source for PHF data structures at compile time.

The provided builders are intended to be used in a Cargo build script to generate a Rust source file that will be included in a library at build time.

Examples

build.rs

extern crate phf_codegen;

use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::AsPath;
use std::env;

fn main() {
    let path = env::var_os("OUT_DIR").unwrap().as_path().join("codegen.rs");
    let mut file = BufWriter::new(File::create(&path).unwrap());

    write!(&mut file, "static KEYWORDS: phf::Map<&'static str, Keyword> = ").unwrap();
    phf_codegen::Map::new()
        .entry("loop", "Keyword::Loop")
        .entry("continue", "Keyword::Continue")
        .entry("break", "Keyword::Break")
        .entry("fn", "Keyword::Fn")
        .entry("extern", "Keyword::Extern")
        .build(&mut file)
        .unwrap();
    write!(&mut file, ";\n").unwrap();
}

lib.rs

extern crate phf;

#[derive(Clone)]
enum Keyword {
    Loop,
    Continue,
    Break,
    Fn,
    Extern,
}

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

pub fn parse_keyword(keyword: &str) -> Option<Keyword> {
    KEYWORDS.get(keyword).cloned()
}