use serde::{Deserialize,Serialize};
#[derive(Deserialize, Serialize, Debug, PartialEq, PartialOrd)]
pub struct PluginIndentifier<'a> {
pub name: &'a str,
pub is_standard_library_supported: bool,
pub version: Option<&'a str>,
pub apply: Option<bool>,
}
impl<'a> PluginIndentifier<'a> {
pub const fn new(name: &'a str, is_standard_library_supported: bool) -> Self {
PluginIndentifier {
name,
is_standard_library_supported,
version: None,
apply: None,
}
}
pub const fn with_version(mut self, version: &'a str) -> Self {
self.version = Some(version);
self
}
pub const fn with_apply(mut self, apply: bool) -> Self {
self.apply = Some(apply);
self
}
}
impl std::fmt::Display for PluginIndentifier<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let prefix = if self.is_standard_library_supported { "kotlin" }
else { "id" };
let version = match self.version {
None => String::new(),
Some(value) => format!("version \"{}\"",value),
};
let apply = match self.apply {
None => String::new(),
Some(value) => format!("apply \"{}\"",value.to_string()),
};
write!(f,"{}(\"{}\") {} {}",&prefix,self.name,version,apply)?;
Ok(())
}
}