From fbbb53094e52efa19ff225d3d3ef2cbc00b4a7af Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 17 Feb 2015 22:18:10 -0800 Subject: [PATCH] Add example to root module docs --- phf/src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/phf/src/lib.rs b/phf/src/lib.rs index b8d5f1d7..0d68bfe9 100644 --- a/phf/src/lib.rs +++ b/phf/src/lib.rs @@ -2,6 +2,37 @@ //! //! Keys can be string literals, byte string literals, byte literals, char //! literals, or any of the fixed-size isizeegral types. +//! +//! # Examples +//! +//! ```rust +//! #![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 { +//! KEYWORDS.get(keyword).map(|t| t.clone()) +//! } +//! # fn main() {} +//! ``` #![doc(html_root_url="https://sfackler.github.io/rust-phf/doc")] #![feature(core, no_std)] #![warn(missing_docs)]