2 unstable releases

0.2.0 Aug 15, 2022
0.1.0 Oct 17, 2019

#136 in #document

Download history 28/week @ 2023-12-18 3/week @ 2024-01-22 15/week @ 2024-01-29 16/week @ 2024-02-12 19/week @ 2024-02-19 44/week @ 2024-02-26 15/week @ 2024-03-04 21/week @ 2024-03-11 24/week @ 2024-03-18 43/week @ 2024-03-25 71/week @ 2024-04-01

162 downloads per month
Used in yolol-yaml-deserializer

MIT license

39KB
774 lines

crates.io docs.rs

libyaml

This Rust crate provides high-level bindings for the LibYAML library via the unsafe-libyaml crate. It has the following limitations:

  • the token and document APIs are currently not implemented.

Installation

Just add this crate to your Cargo.toml:

[dependencies]
libyaml = "0.2"

You do not need to install the LibYAML library on the target system. Instead, unsafe-libyaml provides a transpiled version.

License

This crate is licensed under the MIT license.


lib.rs:

High-level bindings for the LibYAML library.

Reading YAML

To read a YAML stream, use Parser. This example counts the number of alias events in a stream.

#
let alias_count = Parser::new(reader)?.into_iter().filter(|e| {
    if let Ok(Event::Alias { .. }) = e { true } else { false }
}).count();

Writing YAML

To write a YAML stream, use Emitter. This example writes a stream with a single document consisting of a single scalar.

#
let mut emitter = Emitter::new(writer)?;

emitter.emit(Event::StreamStart { encoding: None })?;
emitter.emit(Event::DocumentStart { implicit: true })?;
emitter.emit(Event::Scalar {
    anchor: None,
    tag: Some(tag::INT.to_string()),
    value: "42".to_string(),
    plain_implicit: false,
    quoted_implicit: false,
    style: None,
})?;
emitter.emit(Event::DocumentEnd { implicit: true })?;
emitter.emit(Event::StreamEnd)?;

Dependencies

~440KB
~11K SLoC