Flat file database editor and browser with web interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rocket-inv/src/store/model.rs

97 lines
2.4 KiB

use std::collections::HashMap;
use indexmap::map::IndexMap;
/// A data card's model.
/// Cards of one model can be sorted, searched and filtered by their fields.
#[derive(Deserialize, Debug)]
pub struct Model {
/// Fields defined by this model
pub fields: IndexMap<String, Field>,
}
/// One field of a model
#[derive(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<i64>,
/// Highest allowed value
#[serde(default)]
max: Option<i64>,
/// Default value
#[serde(default)]
default: i64,
},
/// Floating point entry
Float {
/// Lowest allowed value
#[serde(default)]
min: Option<f64>,
/// Highest allowed value
#[serde(default)]
max: Option<f64>,
/// 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<String>,
/// Default option (if not the first)
#[serde(default)]
default: Option<String>,
},
/// 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<String>,
},
/// Tags with a fixed set of options to choose from
Tags {
/// Options to choose from
options: Vec<String>,
},
/// 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<String>,
},
}