json_forge!() { /* proc-macro */ }Expand description
Generate Rust data structures from a JSON file on disk.
§Usage
ⓘ
json_forge! {
path = "relative/path/to/data.json", // relative to CARGO_MANIFEST_DIR
name = "MyEntry", // name for the generated struct
vis = pub, // struct visibility (default: pub)
data_vis = pub(crate), // data visibility (default: same as vis)
embedded = false, // override embedded mode
}§Visibility
Both vis and data_vis accept pub, pub(crate), pub(super), pub(self), or
private (no visibility modifier). When data_vis is omitted it defaults to vis.
§Embedded mode
Without the embedded feature (or embedded = false), this emits:
- A struct
MyEntry { … }with owned field types (String,Vec<T>, etc.). - A
const MY_ENTRY_JSON: &strcontaining the raw JSON viainclude_str!.
With the embedded feature enabled (or embedded = true), this emits:
- A struct
MyEntry { … }with&'static str/&'static [T]fields. - A
static MY_ENTRY: ::phf::Map<&'static str, MyEntry>(for top-level objects) or a fixed-length array static (for top-level arrays).
embedded = true requires the embedded Cargo feature; embedded = false forces
runtime mode even when the feature is active.
§Consumer note for embedded mode
The generated code references ::phf::Map. Add phf = "0.13" to the dependencies
of the crate that invokes the macro.