YAML_lib ๐ฆ
A comprehensive, high-performance YAML library for Rust that provides full YAML 1.2 specification compliance with excellent ergonomics and extensive format conversion capabilities.
โจ Features
๐ฏ Core YAML Support
- Full YAML 1.2 specification compliance
- Unicode-aware parsing with BOM detection
- Multi-document streams support
- Anchors and aliases with circular reference detection
- Block and flow syntax parsing
- Comments preservation throughout parsing
- All scalar types: strings, integers, floats, booleans, null
- All collection types: sequences, mappings, sets
๐ท๏ธ Advanced Tag Support
- Standard YAML tags:
!!str,!!int,!!float,!!bool,!!null - Collection tags:
!!seq,!!map,!!set - Binary data:
!!binarywith base64 validation - Ordered mappings:
!!omapfor insertion-order preservation - Key-value pairs:
!!pairswith duplicate key support - Merge keys:
!!mergefor YAML inheritance - Numeric bases: hexadecimal (
!!int:hex) and octal (!!int:oct) - Custom tags: preservation and round-trip support
๐ Multi-Format Conversion
- YAML โ Native format with pretty-printing
- JSON โ With pretty-printing support
- XML โ With configurable formatting
- TOML โ With table structure preservation
- Bencode โ For BitTorrent applications
๐ Performance & Safety
- Zero-copy parsing where possible
- Memory-efficient node representation
- Thread-safe operations
- Error recovery and detailed diagnostics
- Comprehensive test suite (362+ tests)
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.6"
๐ Quick Start
Basic Parsing
use *;
Working with Nodes
use *;
File Operations
use *;
Advanced Features
use *;
๐ API Reference
Core Types
Node- The fundamental data structure representing any YAML valueNumeric- Enum for integer and floating-point numbersBufferSource/FileSource- Input sources for parsingBufferDestination/FileDestination- Output destinations for serialization
Key Functions
| Function | Description |
|---|---|
parse() |
Parse YAML from any source into a Node tree |
stringify() |
Convert Node tree back to YAML format |
to_json() / to_json_pretty() |
Convert to JSON format |
to_xml() / to_xml_pretty() |
Convert to XML format |
to_toml() / to_toml_pretty() |
Convert to TOML format |
to_bencode() |
Convert to Bencode format |
make_node() |
Helper macro for creating nodes |
make_set() |
Create set nodes with duplicate removal |
File Utilities
| Function | Description |
|---|---|
read_file_to_string() |
Read file with automatic encoding detection |
write_file_from_string() |
Write file with specified encoding |
detect_format() |
Detect Unicode format from BOM |
๐ฏ Examples
The repository includes comprehensive examples:
- yaml_parse_and_stringify - Basic parsing and serialization
- yaml_to_json - YAML to JSON conversion
- yaml_to_xml - YAML to XML conversion
- yaml_to_bencode - YAML to Bencode conversion
- yaml_fibonacci - Advanced YAML generation
- yaml_utility_lib - Library usage patterns
Run examples:
๐งช Testing
The library includes an extensive test suite with 362+ tests covering:
- Basic parsing - All YAML constructs and edge cases
- Document structure - Multi-document streams, markers, directives
- Tag coercion - All standard and custom tags
- Error handling - Malformed YAML and recovery
- File parsing - Different encodings and formats
- Nested structures - Deep nesting and complex documents
- Flow syntax - Inline sequences and mappings
- Set operations - Unique collections and operations
# Run all tests
# Run specific test categories
# Run with output
๐ง Performance
YAML_lib is designed for performance:
- Lazy parsing - Only parse what you need
- Memory efficiency - Minimal allocations and copying
- Zero-copy strings - Where possible, reference original data
- Optimized algorithms - Efficient parsing and serialization
- Minimal dependencies - Only
randfor testing utilities
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
Code Guidelines
- Follow standard Rust formatting (
cargo fmt) - Ensure all tests pass (
cargo test) - Add tests for new functionality
- Update documentation as needed
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- YAML 1.2 Specification - yaml.org
- Rust Community - For excellent tooling and ecosystem
- Contributors - Everyone who helped improve this library
๐ Project Stats
- Language: Rust ๐ฆ
- Minimum Rust Version: 1.88.0
- Lines of Code: ~10,000+
- Test Coverage: 362+ tests
- Documentation: Comprehensive inline docs
- Examples: 6 comprehensive examples
Made with โค๏ธ and ๐ฆ by the YAML_lib team
For questions, issues, or contributions, please visit our GitHub repository.