#yaml #serde-yaml #serialization

no-std bin+lib libyml

A safe and efficient Rust library for parsing, emitting, and manipulating YAML data

5 releases

0.0.5 Aug 24, 2024
0.0.4 Jul 20, 2024
0.0.3 May 28, 2024
0.0.2 May 28, 2024
0.0.1 Apr 28, 2024

#199 in Parser implementations

Download history 5332/week @ 2024-07-18 6231/week @ 2024-07-25 5879/week @ 2024-08-01 8880/week @ 2024-08-08 9279/week @ 2024-08-15 12521/week @ 2024-08-22 13516/week @ 2024-08-29 13949/week @ 2024-09-05 13174/week @ 2024-09-12 14344/week @ 2024-09-19 13970/week @ 2024-09-26 16230/week @ 2024-10-03 16316/week @ 2024-10-10 20310/week @ 2024-10-17 22395/week @ 2024-10-24 22392/week @ 2024-10-31

84,430 downloads per month
Used in 142 crates (via serde_yml)

MIT license

565KB
13K SLoC

LibYML logo

LibYML (a fork of unsafe-libyaml)

Made With Love Crates.io lib.rs Docs.rs Codecov Build Status GitHub

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.

Features

  • Serialization and Deserialization: Easy-to-use APIs for serializing Rust structs and enums to YAML and vice versa.
  • Custom Struct and Enum Support: Seamless serialization and deserialization of custom data types.
  • Comprehensive Error Handling: Detailed error messages and recovery mechanisms.
  • Streaming Support: Efficient processing of large YAML documents.
  • Alias and Anchor Support: Handling of complex YAML structures with references.
  • Tag Handling: Support for custom tags and type-specific serialization.
  • Configurable Emitter: Customizable YAML output generation.
  • Extensive Documentation: Detailed docs and examples for easy onboarding.
  • Safety and Efficiency: Minimized unsafe code with an interface designed to prevent common pitfalls.

Installation

Add this to your Cargo.toml:

[dependencies]
libyml = "0.0.5"

Usage

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
        }
    }
}

Documentation

For full API documentation, please visit https://doc.libyml.com/libyml/ or https://docs.rs/libyml.

Rust Version Compatibility

Compiler support: requires rustc 1.56.0+

Contributing

Contributions are welcome! If you'd like to contribute, please feel free to submit a Pull Request on GitHub.

Credits and Acknowledgements

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.

License

MIT license, same as libyaml.

Dependencies