forked from Cutieguwu/raven
Most of the refactor. Need to switch machines.
This commit is contained in:
62
retired/nest_lib_rs_old/meta.rs
Normal file
62
retired/nest_lib_rs_old/meta.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use std::fmt::Display;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Meta {
|
||||
name: String,
|
||||
version: semver::Version,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
authors: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
repository: Option<String>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
license: Option<License>,
|
||||
#[serde(skip_serializing_if = "<Option<_>>::is_none")]
|
||||
license_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
pub fn new<S: ToString>(name: S) -> Self {
|
||||
let mut meta = Self::default();
|
||||
meta.name = name.to_string();
|
||||
meta
|
||||
}
|
||||
|
||||
pub fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Meta {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: Default::default(),
|
||||
version: semver::Version::new(0, 1, 0),
|
||||
authors: None,
|
||||
repository: None,
|
||||
license: None,
|
||||
license_file: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
|
||||
pub enum License {
|
||||
Mit,
|
||||
Apache,
|
||||
}
|
||||
|
||||
impl Display for License {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
License::Mit => "MIT",
|
||||
License::Apache => "Apache",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user