use error;
use std::fs::File;
use std::io::{BufRead, BufReader};
#[derive(Debug)]
pub struct Snippet {
pub name: String,
pub tags: Vec<String>,
}
impl Snippet {
pub fn new(name: String, tags: &Vec<String>) -> Snippet {
Snippet {
name,
tags: tags.to_owned(),
}
}
}
pub fn read_tags(path: &str) -> Result<Vec<String>, error::Error> {
let f = File::open(path)?;
let mut file = BufReader::new(f);
let mut buffer = String::new();
file.read_line(&mut buffer)?;
let mut t: Vec<&str> = buffer.as_str().split(',').map(|s| s.trim()).collect();
t.retain(|s| !s.is_empty());
let tags: Vec<String> = t.iter().map(|s| String::from(s.to_owned())).collect();
Ok(tags)
}