use std::collections::HashMap; /// A data card's model. /// Cards of one model can be sorted, searched and filtered by their fields. #[derive(Serialize, Deserialize, Debug)] pub struct Model { /// Fields defined by this model pub fields: HashMap, } /// One field of a model #[derive(Serialize, Deserialize, Debug)] pub struct Field { /// Field label shown in the user interface #[serde(default)] pub label: String, /// Field data type #[serde(flatten)] pub kind: FieldKind, } /// Field data type and validations #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "type")] #[serde(rename_all = "snake_case")] pub enum FieldKind { /// Single-line text entry String, /// Long-form text entry, can have multiple rows Text, /// Checkbox or a toggle switch Bool { /// Default value when the model's card is created #[serde(default)] default: bool, }, /// Integer entry Int { /// Lowest allowed value #[serde(default)] min: Option, /// Highest allowed value #[serde(default)] max: Option, /// Default value #[serde(default)] default: i64, }, /// Floating point entry Float { /// Lowest allowed value #[serde(default)] min: Option, /// Highest allowed value #[serde(default)] max: Option, /// Default value #[serde(default)] default: f64, }, /// Enumeration entry with a fixed set of options Enum { /// Options to choose from, must not be empty options: Vec, /// Default option (if not the first) #[serde(default)] default: Option, }, /// Enum that can be freely expanded by the user FreeEnum { /// Group name. /// If not set, a private group for this particular field is used. #[serde(default)] enum_group: Option, }, /// Tags with a fixed set of options to choose from Tags { /// Options to choose from options: Vec, }, /// Tags that can be freely added by the user FreeTags { /// Group name. /// If not set, a private group for this particular field is used. #[serde(default)] tag_group: Option, }, }