Skip to content

Instantly share code, notes, and snippets.

@SpamapS
Last active December 28, 2016 01:00
Show Gist options
  • Save SpamapS/ca087da2133ed11356031487b82bb566 to your computer and use it in GitHub Desktop.
Save SpamapS/ca087da2133ed11356031487b82bb566 to your computer and use it in GitHub Desktop.
$ cargo build
Compiling phfoo v0.1.0 (file:///home/clint/src/rustplay/phf/phfoo)
error[E0463]: can't find crate for `phf_macros`
--> src/main.rs:2:11
|
2 | #![plugin(phf_macros)]
| ^^^^^^^^^^ can't find crate
error: aborting due to previous error
error: Could not compile `phfoo`.
To learn more, run the command again with --verbose.
#![feature(plugin)]
#![plugin(phf_macros)]
extern crate phf;
#[derive(Clone)]
pub enum Keyword {
Loop,
Continue,
Break,
Fn,
Extern,
}
static KEYWORDS: phf::Map<&'static str, Keyword> = phf_map! {
"loop" => Keyword::Loop,
"continue" => Keyword::Continue,
"break" => Keyword::Break,
"fn" => Keyword::Fn,
"extern" => Keyword::Extern,
};
pub fn parse_keyword(keyword: &str) -> Option<Keyword> {
KEYWORDS.get(keyword).cloned()
}
fn main() {
match KEYWORDS.get("loop") {
Keyword::Loop => println!("The cow says loop"),
_ => println!("The cow has mad cow disease"),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment