Rust challenge 51/100 - parsing yaml
Table of content
What is this
The rules of the game are explained in my original. I haven’t posted in a while but I want to get started again.
51st Challenge
Challenge
Today the challenge is to parse and extract information from a yaml. And not just any yaml, all the yamls in the repos things network lorawan devices. Bonus: make some statistics from the files. Lets get started.
Solution
This was failry simple but fun. The hard work was done by the yaml rust.
extern crate yaml_rust;
use yaml_rust::{YamlLoader, YamlEmitter};
fn main() {
let vendor_yaml_url = "https://raw.githubusercontent.com/TheThingsNetwork/lorawan-devices/master/vendor/index.yaml";
let vendor_yaml = reqwest::blocking::get(vendor_yaml_url).unwrap().text().unwrap();
let vendors = YamlLoader::load_from_str(&vendor_yaml).unwrap();
let vendors = vendors[0]["vendors"].clone();
/* minus 1 because there is a "example" vendor */
let vendor_count = vendors.as_vec().unwrap().len()-1;
println!("There are currently {} vendors in the Things Network device repository. ", vendor_count);
}
See github for today’s simple snippet.