What is up with yaml support in rust?

Hello!
I need to parse some yaml files for my little Rust project and also convert the yaml ast into a string. Are there any crates for working with Yaml which are alive or reached the usable state?

I recommend the serde_yaml crate.

Or if you ned to parse/emit yaml directly instead of serializing to yaml, use yaml-rust

1 Like

But any serde crate is for converting a stream of data into a struct. I'd like to interact with Yaml's AST directly...

I checked it. It seems like it wasn't updated for a year. I know that's not a big problem and can be implemented with some little trickery, but it doesn't any straightforward way of converting the Yaml AST into a string

serde-yaml depends on yaml-rust, so I think that this is fine.

From the example on the crates.io page

    // Dump the YAML object
    let mut out_str = String::new();
    {
        let mut emitter = YamlEmitter::new(&mut out_str);
        emitter.dump(doc).unwrap(); // dump the YAML object to a String
    }
    println!("{}", out_str);

As far as I can see, the Yaml AST is represented with the Yaml enum, which you can emit using the emitter as in @RustyYato's example. I don't think it is a problem for it's last update to be a year ago if it is already feature complete.

Huh. Didn't notice it. Thank you for your help!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.