1use error;
2use std::fs::File;
3use std::io::{BufRead, BufReader};
4
5#[derive(Debug)]
9pub struct Snippet {
10 pub name: String,
11 pub tags: Vec<String>,
12}
13
14impl Snippet {
15 pub fn new(name: String, tags: &Vec<String>) -> Snippet {
16 Snippet {
17 name,
18 tags: tags.to_owned(),
19 }
20 }
21}
22
23pub fn read_tags(path: &str) -> Result<Vec<String>, error::Error> {
24 let f = File::open(path)?;
26 let mut file = BufReader::new(f);
27
28 let mut buffer = String::new();
30 file.read_line(&mut buffer)?;
31
32 let mut t: Vec<&str> = buffer.as_str().split(',').map(|s| s.trim()).collect();
34 t.retain(|s| !s.is_empty());
35
36 let tags: Vec<String> = t.iter().map(|s| String::from(s.to_owned())).collect();
37
38 Ok(tags)
40}