Crates.io | libyml |
lib.rs | libyml |
version | 0.0.5 |
source | src |
created_at | 2024-04-28 22:30:31.580391 |
updated_at | 2024-08-24 12:41:49.519714 |
description | A safe and efficient Rust library for parsing, emitting, and manipulating YAML data. |
homepage | https://libyml.com |
repository | https://github.com/sebastienrousseau/libyml |
max_upload_size | |
id | 1223563 |
size | 681,939 |
LibYML is a Rust library for working with YAML data, forked from unsafe-libyaml. It offers a safe and efficient interface for parsing, emitting, and manipulating YAML data.
Add this to your Cargo.toml
:
[dependencies]
libyml = "0.0.5"
Here's a quick example on how to use LibYML to parse a YAML string:
use core::mem::MaybeUninit;
use libyml::{
success::is_success,
yaml_parser_delete,
yaml_parser_initialize,
yaml_parser_parse,
yaml_parser_set_input_string,
YamlEventT,
YamlParserT,
};
fn main() {
unsafe {
let mut parser = MaybeUninit::<YamlParserT>::uninit();
if is_success(yaml_parser_initialize(parser.as_mut_ptr())) {
let mut parser = parser.assume_init();
let yaml = "{key1: value1, key2: [item1, item2]}";
yaml_parser_set_input_string(
&mut parser,
yaml.as_ptr(),
yaml.len() as u64,
);
let mut event = MaybeUninit::<YamlEventT>::uninit();
let result = yaml_parser_parse(&mut parser, event.as_mut_ptr());
if is_success(result) {
// Process the event here
} else {
// Failed to parse YAML
}
yaml_parser_delete(&mut parser);
} else {
// Failed to initialize parser
}
}
}
For full API documentation, please visit https://doc.libyml.com/libyml/ or https://docs.rs/libyml.
Compiler support: requires rustc 1.56.0+
Contributions are welcome! If you'd like to contribute, please feel free to submit a Pull Request on GitHub.
LibYML is a fork of the work done by David Tolnay and the maintainers of unsafe-libyaml. While it has evolved into a separate library, we express our sincere gratitude to them as well as the libyaml maintainers for their contributions to the Rust and C programming communities.
MIT license, same as libyaml.