1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Shared field-spec types used by the universal config (`opys.toml`). See
//! [`crate::project_config`] for the engine config.
use serde::Deserialize;
/// Declared type of a custom frontmatter field.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum FieldType {
#[default]
String,
List,
Bool,
Int,
/// A string constrained to the declared `values` set (see [`FieldSpec`]).
Enum,
}
impl FieldType {
pub fn as_str(self) -> &'static str {
match self {
FieldType::String => "string",
FieldType::List => "list",
FieldType::Bool => "bool",
FieldType::Int => "int",
FieldType::Enum => "enum",
}
}
}
/// Declaration of a project-specific frontmatter field (a type's `[fields.*]`).
#[derive(Debug, Clone, Deserialize)]
pub struct FieldSpec {
#[serde(default, rename = "type")]
pub field_type: FieldType,
#[serde(default)]
pub required: bool,
#[serde(default)]
pub description: Option<String>,
/// Allowed values for an `enum` field; ignored for other types.
#[serde(default)]
pub values: Vec<String>,
/// Optional regex a `string` value must fully match.
#[serde(default)]
pub pattern: Option<String>,
}