Last active
December 28, 2016 01:00
-
-
Save SpamapS/ca087da2133ed11356031487b82bb566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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