Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
/ rust-phf Public archive
forked from rust-phf/rust-phf

Compile time static maps for Rust

License

Notifications You must be signed in to change notification settings

servo/rust-phf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust-PHF

Build Status

Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions.

It currently uses the CHD algorithm and can generate a 10,000 entry map in roughly .25 seconds.

Documentation is available at http://www.rust-ci.org/sfackler/rust-phf/doc/phf/.

Example

#![feature(phase)]

#[phase(syntax)]
extern crate phf_mac;
extern crate phf;

use phf::PhfMap;

static KEYWORDS: PhfMap<&'static str, Keyword> = phf_map! {
    "loop" => LOOP,
    "continue" => CONTINUE,
    "break" => BREAK,
    "fn" => FN,
    "extern" => EXTERN,
};

pub fn parse_keyword(keyword: &str) -> Option<Keyword> {
    KEYWORDS.find_equiv(keyword).map(|t| t.clone())
}

About

Compile time static maps for Rust

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%