Skip to content

Item lists example #21

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions examples/item_lists.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
extern crate quire;
#[macro_use] extern crate serde_derive;
use quire::{parse_config, Options};
use quire::validate::{Structure, Scalar};

#[derive(Deserialize)]
#[allow(dead_code)]
struct Journey {
name: String,
year: String,
team: Members,
}

#[derive(Deserialize)]
#[allow(dead_code)]
struct Members(Vec<String>);

// give it a method
// so we can create a iterator for it
#[allow(dead_code)]
impl Members {
fn new() -> Members {
Members(Vec::new())
}
}

// and implement IntoIterator
impl IntoIterator for Members {
type Item = String;
type IntoIter = ::std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

fn validator() -> Structure<'static> {
Structure::new()
.member("name", Scalar::new())
.member("year", Scalar::new())
.member("team", Scalar::new())
}

fn work(jrny: &Journey) {
println!("name is {}.", jrny.name);
println!("year is {}.", jrny.year);
/*
for tm in jrny.team {
println!("team member {}.", tm);
}
*/
}

fn main() {
let jrny: Journey;
jrny = parse_config("examples/journey.yaml",
&validator(), &Options::default())
.expect("valid config");
work(&jrny)
}
22 changes: 22 additions & 0 deletions examples/journey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# journey.yaml
# "configuration" for item_lists

---
name: Voyage Voyage
year: 2020
_team:
- Alice
- Bob
- Claire
- David
_vehicles:
- Jeep
- Landrover
_locations:
- Home
- Sweet
- Home

...
# l l