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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
use serde::Serialize;
use std::path::PathBuf;
/// The package contributes
#[derive(Debug, Clone, Serialize)]
pub struct Contributes {
pub snippets: Vec<SnippetsContribute>,
}
impl Contributes {
/// Creates a new package contributes
pub fn new() -> Self {
Self {
snippets: vec![],
}
}
/// Registrates a new snippets file
pub fn reg_snippets(&mut self, contribute: SnippetsContribute) {
self.snippets.push(contribute);
}
}
/// The snippets contribute object
/// * language - the snippets programming language
/// * path - the snippets file path
#[derive(Debug, Clone, Serialize)]
pub struct SnippetsContribute {
pub language: String,
pub path: PathBuf,
}
impl SnippetsContribute {
/// Creates a new snippets contributes object
/// * lang - the snippets programming language
/// * file_name - the file_name to the snippets file
pub fn new<S, P>(lang: S, file_name: P) -> Self
where S: Into<String>, P: Into<PathBuf> {
let path = PathBuf::from("snippets").join( &file_name.into() );
Self {
language: lang.into(),
path,
}
}
}