Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON recipe #555

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build = "build.rs"
[dependencies]
byteorder = "1.0.0"
error-chain = "0.8.0"
json = "0.11.5"

[build-dependencies]
skeptic = "0.6"
Expand Down
117 changes: 0 additions & 117 deletions README.md

This file was deleted.

12 changes: 11 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
extern crate skeptic;

use std::fs;

fn main() {
skeptic::generate_doc_tests(&["README.md"]);
let paths = fs::read_dir("./pages/").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is meant to resolve some of the errors we are experiencing I'd really appreciate it broken out of the addition of examples


for path in paths {
let p = path.unwrap().path();
let s = p.to_str().unwrap();
if s.contains(".md") {
skeptic::generate_doc_tests(&[s])
}
}
}
52 changes: 52 additions & 0 deletions pages/json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#JSON

##JSON implementation in Rust:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind including a sentence or two about what this recipe demonstrates, please include links to the primary sources of documentation.


[![json][json-badge]][json]

```rust
#[macro_use]
extern crate json;

fn main() {

let parsed = json::parse(r#"

{
"code": 200,
"success": true,
"payload": {
"features": [
"awesome",
"easyAPI",
"lowLearningCurve"
]
}
}

"#).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see proper error handling in cookbook.


let instantiated = object!{
"code" => 200,
"success" => true,
"payload" => object!{
"features" => array![
"awesome",
"easyAPI",
"lowLearningCurve"
]
}
};

assert_eq!(parsed, instantiated);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than comparing the object is equal, please show how to traverse the JSON document to compare individual pieces of data.


}
```
# License

MIT/Apache-2.0

<!-- Links -->
[json-badge]: https://img.shields.io/crates/v/rustc-serialize.svg?label=json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the badges are in /src/links.md

[json]: http://json.rs/doc/json/