Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing usage examples #19

Open
busstoptaktik opened this issue Jan 21, 2021 · 0 comments
Open

Missing usage examples #19

busstoptaktik opened this issue Jan 21, 2021 · 0 comments

Comments

@busstoptaktik
Copy link

busstoptaktik commented Jan 21, 2021

As yaml_rust seems unmaintained, I'm considering switching to minimal-yaml. But as a relative newbie to Rust, I have problems figuring out how to access elements in the minimal-yaml representation.

With yaml_rust, I do stuff like this:

    let txt = std::fs::read_to_string("src/simple.yml").unwrap();
    let docs = YamlLoader::load_from_str(&txt).unwrap();

    // Sequence
    let steps = docs[0]["recipe"]["steps"].as_vec().unwrap();
    for s in steps {
        ...
    }

    // Mapping
    let globals = docs[0]["recipe"]["globals"].as_hash().unwrap();
    let iter = globals.iter();
    for (arg, val) in iter {
        ...
    }

With minimal-yaml, I can get as far as:

    let txt = std::fs::read_to_string("src/simple.yml").unwrap();
    let rep = parse(&txt).unwrap();

    // This works as expected
    println!("{:?}", rep);

But I cannot figure out how to loop/search the representation with minimal-yaml. To get me started, a few usage examples in the documentation would be very helpful.

    // But how can I do this properly?
    for r in &rep {
        println!("r: {:?}", dd);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant