use std::path::PathBuf;
use structopt::StructOpt;
use serde::{Serialize, Deserialize};
#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
#[structopt(short, long)]
debug: bool,
#[structopt(short, long, parse(from_occurrences))]
verbose: u8,
#[structopt(short, long, default_value = "42")]
speed: f64,
#[structopt(short, long, parse(from_os_str))]
output: PathBuf,
#[structopt(short = "c", long)]
nb_cars: Option<i32>,
#[structopt(short, long)]
level: Vec<String>,
#[structopt(name = "FILE", parse(from_os_str))]
files: Vec<PathBuf>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Point {
x: f64,
y: f64,
}
fn serialize_and_deserialize_point() -> Result<(), serde_yaml::Error> {
let point = Point { x: 1.0, y: 2.0 };
let s = serde_yaml::to_string(&point)?;
assert_eq!(s, "---\nx: 1.0\ny: 2.0");
let deserialized_point: Point = serde_yaml::from_str(&s)?;
assert_eq!(point, deserialized_point);
Ok(())
}
fn main() {
let opt = Opt::from_args();
println!("{:#?}", opt);
match serialize_and_deserialize_point() {
Err(_e) => println!("Failure"),
Ok(_r) => println!("Success"),
}
}