docs.rs failed to build json_str-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
json_str-0.5.2
Json String Literal Generator
Write json with Rust syntax instead of hard to read inline strings.
Results are converted to a &'static str
at compile-time.
Usage
This crate is on crates.io.
To get started, add json_str
to your Cargo.toml
:
[dependencies]
json_str = "*"
And reference it in your crate root:
#![feature(plugin)]
#![plugin(json_str)]
The json_str!
macro will take an inline token tree and return an str
literal:
# #![feature(plugin)]
# #![plugin(json_str)]
# fn main() {
let json = json_str!({
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "20km",
"location": {
"lat": 37.776,
"lon": -122.41
}
}
}
}
}
});
# }
This will also work for unquoted keys for something a bit more rusty
:
# #![feature(plugin)]
# #![plugin(json_str)]
# fn main() {
let json = json_str!({
query: {
filtered: {
query: {
match_all: {}
},
filter: {
geo_distance: {
distance: "20km",
location: {
lat: 37.776,
lon: -122.41
}
}
}
}
}
});
# }
For json values that can't be fully determined at compile-time, use json_macros instead.