Update Readme.md
This commit is contained in:
parent
51f3a66dd2
commit
464200438c
1 changed files with 13 additions and 2 deletions
|
@ -10,6 +10,9 @@ any FFI and crate dependencies, which enjoys the memory safe
|
||||||
property and other benefits from the Rust language.
|
property and other benefits from the Rust language.
|
||||||
The parser is heavily influenced by `libyaml` and `yaml-cpp`.
|
The parser is heavily influenced by `libyaml` and `yaml-cpp`.
|
||||||
|
|
||||||
|
This crate works on all Rust supported platforms and
|
||||||
|
Rust 1.0.0 and nightly!
|
||||||
|
|
||||||
NOTE: This library is still under heavily development.
|
NOTE: This library is still under heavily development.
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
@ -32,7 +35,7 @@ as Vec/HashMap:
|
||||||
|
|
||||||
```.rust
|
```.rust
|
||||||
extern crate yaml_rust;
|
extern crate yaml_rust;
|
||||||
use yaml_rust::yaml;
|
use yaml_rust::{YamlLoader, YamlEmitter};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s =
|
let s =
|
||||||
|
@ -44,7 +47,7 @@ bar:
|
||||||
- 1
|
- 1
|
||||||
- 2.0
|
- 2.0
|
||||||
";
|
";
|
||||||
let docs = yaml::YamlLoader::load_from_str(s).unwrap();
|
let docs = YamlLoader::load_from_str(s).unwrap();
|
||||||
|
|
||||||
// Multi document support, doc is a yaml::Yaml
|
// Multi document support, doc is a yaml::Yaml
|
||||||
let doc = &docs[0];
|
let doc = &docs[0];
|
||||||
|
@ -59,6 +62,14 @@ bar:
|
||||||
// Chained key/array access is checked and won't panic,
|
// Chained key/array access is checked and won't panic,
|
||||||
// return BadValue if they are not exist.
|
// return BadValue if they are not exist.
|
||||||
assert!(doc["INVALID_KEY"][100].is_badvalue());
|
assert!(doc["INVALID_KEY"][100].is_badvalue());
|
||||||
|
|
||||||
|
// Dump the YAML object
|
||||||
|
let mut out_str = String::new();
|
||||||
|
{
|
||||||
|
let mut emitter = YamlEmitter::new(&mut out_str);
|
||||||
|
emitter.dump(doc).unwrap(); // dump the YAML object to a String
|
||||||
|
}
|
||||||
|
println!("{}", out_str);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue