Skip to content

Commit

Permalink
Mention build-dependencies on phf_codegen
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
  • Loading branch information
JohnTitor committed Sep 28, 2022
1 parent 250c6b4 commit 307ef77
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ work as you want. See [#183] or [#196] for example.

### phf_codegen

build.rs:
To use `phf_codegen` on build.rs, you have to add dependencies under `[build-dependencies]`:

```toml
[build-dependencies]
phf = { version = "0.11.1", default-features = false }
phf_codegen = "0.11.1"
```

Then put code on build.rs:

```rust
use std::env;
Expand Down Expand Up @@ -101,7 +109,7 @@ fn main() {
}
```

lib.rs:
and lib.rs:

```rust
#[derive(Clone)]
Expand Down
40 changes: 25 additions & 15 deletions phf_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@
//!
//! ## Examples
//!
//! build.rs:
//! To use `phf_codegen` on build.rs, you have to add dependencies under `[build-dependencies]`:
//!
//! ```toml
//! [build-dependencies]
//! phf = { version = "0.11.1", default-features = false }
//! phf_codegen = "0.11.1"
//! ```
//!
//! ```rust,no_run
//! Then put code on build.rs:
//!
//! ```ignore
//! use std::env;
//! use std::fs::File;
//! use std::io::{BufWriter, Write};
Expand All @@ -23,21 +31,23 @@
//! let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
//! let mut file = BufWriter::new(File::create(&path).unwrap());
//!
//! writeln!(
//! write!(
//! &mut file,
//! "static KEYWORDS: phf::Map<&'static str, Keyword> = \n{};\n",
//! 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()
//! ).unwrap();
//! "static KEYWORDS: phf::Map<&'static str, Keyword> = {}",
//! 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()
//! )
//! .unwrap();
//! write!(&mut file, ";\n").unwrap();
//! }
//! ```
//!
//! lib.rs:
//! and lib.rs:
//!
//! ```ignore
//! #[derive(Clone)]
Expand All @@ -62,7 +72,7 @@
//!
//! build.rs:
//!
//! ```rust,no_run
//! ```no_run
//! use std::env;
//! use std::fs::File;
//! use std::io::{BufWriter, Write};
Expand All @@ -88,7 +98,7 @@
//!
//! lib.rs:
//!
//! ```rust,ignore
//! ```ignore
//! #[derive(Clone)]
//! enum Keyword {
//! Loop,
Expand Down
2 changes: 1 addition & 1 deletion phf_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub trait FmtConst {
/// ### Motivation
/// The conventional signature for lookup methods on collections looks something like this:
///
/// ```rust,ignore
/// ```ignore
/// impl<K, V> Map<K, V> where K: PhfHash + Eq {
/// fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: PhfHash + Eq, K: Borrow<T> {
/// ...
Expand Down

0 comments on commit 307ef77

Please sign in to comment.