| Crates.io | yaml-edit |
| lib.rs | yaml-edit |
| version | 0.1.0 |
| created_at | 2025-08-10 16:20:41.295468+00 |
| updated_at | 2025-08-10 16:20:41.295468+00 |
| description | A lossless parser and editor for YAML files |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1789061 |
| size | 16,418,594 |
A Rust library for parsing and editing YAML files while preserving all whitespace, comments, and formatting. Built with the rowan library for lossless syntax trees.
use yaml_edit::Yaml;
use std::str::FromStr;
let input = r#"
# Configuration file
name: my-project
version: 1.0.0
dependencies:
- serde
- tokio
features:
default: []
full:
- "serde"
- "tokio"
"#;
let mut yaml = Yaml::from_str(input).unwrap();
// Access documents
if let Some(doc) = yaml.document() {
if let Some(mapping) = doc.as_mapping() {
// Get values while preserving structure
if let Some(name_node) = mapping.get("name") {
println!("Project name: {}", name_node.text());
}
}
}
// The original formatting is preserved
println!("{}", yaml);