Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Parsing YAML With Serde In Rust

Code

//! ```cargo
//! [dependencies]
//! serde = "1.0.195"
//! serde_yaml = "0.9.30"
//! ```

use serde::Deserialize;
use serde_yaml::Value;

fn main() {
  
  let input = r#"- alfa
- bravo
- charlie"#;
  
  let de = serde_yaml::Deserializer::from_str(input);
  let value = match Value::deserialize(de) {
    Ok(data) => Some(data),
    Err(_e) => None
  };

  dbg!(value);
}

Results

[_active_nvim_run:22] value = Some(
    Sequence [
        String("alfa"),
        String("bravo"),
        String("charlie"),
    ],
)

sadf