- Notifications
You must be signed in to change notification settings - Fork21
saphyr-rs/saphyr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository is home tosaphyr-parser
,saphyr
and soon-to-besaphyr-serde
. These crates provide fully YAML 1.2 compliant parsing andmanipulation, with a focus on correctness, performance and API friendliness (in that order).
saphyr
is the most user-friendly andhigh-level crate, providing quick-and-easy YAML importing, exporting and objectmanipulation.
use saphyr::{LoadableYamlNode,Yaml,YamlEmitter};let docs =Yaml::load_from_str("[1, 2, 3]").unwrap();let doc =&docs[0];// select the first YAML documentassert_eq!(doc[0].as_integer().unwrap(),1);// access elements by indexletmut out_str =String::new();letmut emitter =YamlEmitter::new(&mut out_str);emitter.dump(doc).unwrap();// dump the YAML object to a String
saphyr-parser
is theparser behindsaphyr
. It provides direct access to the parsing process byemittingYAMLevents.It does not include YAML to object mapping, but is a lightweight alternative tosaphyr
for those interested in building directly atop the parser, withouthaving an intermediate conversion to a Rust object. More details on where tostart are availableondoc.rs.
/// Sink of events. Collects them into an array.structEventSink{events:Vec<Event>,}/// Implement `on_event`, pushing into `self.events`.implEventReceiverforEventSink{fnon_event(&mutself,ev:Event){self.events.push(ev);}}/// Load events from a yaml string.fnstr_to_events(yaml:&str) ->Vec<Event>{letmut sink =EventSink{events:Vec::new()};letmut parser =Parser::new_from_str(yaml);// Load events using our sink as the receiver. parser.load(&mut sink,true).unwrap(); sink.events}
This implementation is fully compatible with the YAML 1.2 specification.saphyr-parser
) tests against (and passes) theYAML testsuite.
Sets of licences are available for each of the crates. Due to this projectbeing based on a fork ofchyh1990'syaml-rust
, there are 2 licenses to beincluded if usingsaphyr
orsaphyr-parser
. Refer to the projects' READMEsfor details.
Fork this repository andCreate a Pull Request on Github.You may need to click on "compare across forks" and select your fork's branch.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.
About
A set of crates dedicated to parsing YAML.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.