fplanner/src/app/structure.rs

58 lines
1.3 KiB
Rust
Raw Normal View History

2023-04-28 20:37:03 +00:00
use chrono::prelude::*;
2023-04-28 23:42:55 +00:00
use std::collections::{BTreeMap, HashMap};
2023-04-28 20:37:03 +00:00
use uuid::Uuid;
2023-04-28 23:42:55 +00:00
use super::components::Component;
2023-04-29 01:52:05 +00:00
#[derive(serde::Deserialize, serde::Serialize, PartialEq, Debug)]
2023-04-28 20:37:03 +00:00
pub enum License {
MIT,
GPL,
AGPL,
CNPL,
}
2023-04-29 01:52:05 +00:00
#[derive(serde::Deserialize, serde::Serialize, Clone, Debug)]
2023-04-28 20:37:03 +00:00
#[serde(default)]
pub struct Layer {
pub zindex: usize,
pub label: String,
pub visible: bool,
2023-04-28 23:42:55 +00:00
pub components: HashMap<Uuid, Component>,
2023-04-28 20:37:03 +00:00
}
impl Default for Layer {
fn default() -> Self {
Self {
zindex: 0,
visible: true,
label: String::default(),
2023-04-28 23:42:55 +00:00
components: HashMap::new(),
2023-04-28 20:37:03 +00:00
}
}
}
2023-04-29 01:52:05 +00:00
#[derive(serde::Deserialize, serde::Serialize, Debug)]
2023-04-28 20:37:03 +00:00
#[serde(default)] // if we add new fields, give them default values when deserializing old state
pub struct Project {
pub id: Uuid,
pub name: String,
pub created: DateTime<Utc>,
pub modified: Option<DateTime<Utc>>,
pub license: License,
pub layers: BTreeMap<usize, Layer>,
}
impl Default for Project {
fn default() -> Self {
Self {
id: Uuid::new_v4(),
name: "".to_string(),
created: Utc::now(),
modified: None,
license: License::MIT,
layers: BTreeMap::default(),
}
}
}