1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use serde_derive::Deserialize;
use serde_json::Error;
use std::fs;
use std::io::Read;
#[derive(Deserialize)]
pub struct List {
pub template: String,
pub about: String,
}
impl List {
pub fn read(path: &str) -> Result<Vec<Self>, Error> {
let mut file = fs::File::open(path).expect("Unable to open file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Unable to read file");
let list: Vec<List> = serde_json::from_str(&contents)?;
Ok(list)
}
pub fn list(path: &str) {
let json = Self::read(path).expect("Unable to read list.json");
println!("//////////////////////////////////////");
println!("// List of available templates:");
println!("//////////////////////////////////////");
for item in json {
println!("// {} => {}", item.template, item.about);
}
}
}