phf_codegen 0.6.14

Codegen library for PHF types
docs.rs failed to build phf_codegen-0.6.14
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: phf_codegen-0.11.2

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()
}