Skip to main content

eure_document/
data_model.rs

1use crate::prelude_internal::*;
2
3/// Data model of a document or a value in a document. Corresponds to the `$data-model` extension.
4#[derive(Debug, Clone, Copy, PartialEq, Default)]
5pub enum DataModel {
6    /// Serde compatible data model.
7    Rust,
8    /// JSON compatible data model.
9    Json,
10    /// Eure full data model including path.
11    #[default]
12    Eure,
13}
14
15#[derive(Debug, Clone, PartialEq, Default)]
16pub struct DataModelConfig {
17    pub data_model: DataModel,
18    pub number_key_repr: NumberKeyRepr,
19    pub tuple_key_repr: TupleKeyRepr,
20    pub boolean_key_repr: BooleanKeyRepr,
21    pub tuple_repr: TupleRepr,
22}
23
24#[derive(Debug, Clone, PartialEq, Default)]
25/// How to represent numeric keys in a data model that does not support numbers as object keys. Corresponds to the `$number-key-repr` extension.
26pub enum NumberKeyRepr {
27    /// Represent number as string.
28    String,
29    /// Error on conversion.
30    #[default]
31    Error,
32}
33
34#[derive(Debug, Clone, PartialEq, Default)]
35/// How to represent tuple keys in a data model that does not support tuples as object keys. Corresponds to the `$tuple-key-repr` extension.
36pub enum TupleKeyRepr {
37    /// Represent tuple as string. e.g. "(1,2,3)".
38    String,
39    /// Error on conversion.
40    #[default]
41    Error,
42}
43
44#[derive(Debug, Clone, PartialEq, Default)]
45/// How to represent boolean keys in a data model that does not support booleans as object keys. Corresponds to the `$boolean-key-repr` extension.
46pub enum BooleanKeyRepr {
47    /// Represent boolean as string. e.g. "true" or "false".
48    String,
49    /// Error on conversion.
50    #[default]
51    Error,
52}
53
54#[derive(Debug, Clone, PartialEq, Default)]
55/// How to represent tuples in a data model that does not support tuples. Corresponds to the `$tuple-repr` extension.
56pub enum TupleRepr {
57    /// Represent tuple as array. e.g. "[1,2,3]".
58    Array,
59    /// Represent tuple as number indexed object. e.g. `{0: 1, 1: 2, 2: 3}`. `{"0": 1, "1": 2, "2": 3}` if `NumberKeyRepr` is `String`.
60    NumberIndexedObject,
61    /// Error on conversion.
62    #[default]
63    Error,
64}
65
66/// How to represent text with non-plaintext language in a data model.
67///
68/// This controls how `Text` values with `Language::Other(lang)` are serialized
69/// to formats that don't natively support language-tagged text.
70///
71/// Corresponds to the `$text-repr` extension (formerly `$code-repr`).
72#[derive(Debug, Clone, PartialEq, Default)]
73pub enum TextRepr {
74    /// Markdown code block string.
75    /// e.g. "```rust\nfn main() { println!(\"Hello, world!\"); }\n```".
76    Markdown,
77    /// Content only string, discarding language information.
78    /// e.g. "fn main() { println!(\"Hello, world!\"); }".
79    String,
80    /// Object with language and content fields.
81    /// e.g. `{"language": "rust", "content": "fn main() { println!(\"Hello, world!\"); }"}`.
82    Object {
83        language_key: String,
84        content_key: String,
85    },
86    /// Error on conversion.
87    #[default]
88    Error,
89}