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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pub mod base;
mod constants;
mod dependents;
mod lax;
mod required;
pub mod types;
mod virtuals;
use std::marker::PhantomData;
use crate::{
schema::{
error_tool::IvoErrorTool,
fields::{
constants::ConstantFieldBuilder, dependents::DependentFieldBuilder,
lax::LaxFieldBuilder, required::RequiredFieldBuilder, virtuals::VirtualFieldBuilder,
},
},
types::IvoFieldValue,
IvoSchemaStruct,
};
pub use base::TimestampConfig;
pub struct IvoField<
T: IvoFieldValue,
I: IvoSchemaStruct,
O: IvoSchemaStruct,
CtxOptions,
ErrorTool: IvoErrorTool,
> {
_t: PhantomData<T>,
_i: PhantomData<I>,
_o: PhantomData<O>,
_c: PhantomData<CtxOptions>,
_err: PhantomData<ErrorTool>,
}
impl<
T: IvoFieldValue,
I: IvoSchemaStruct,
O: IvoSchemaStruct,
CtxOptions,
ErrorTool: IvoErrorTool,
> IvoField<T, I, O, CtxOptions, ErrorTool>
{
/// A constant field is one whose value never changes after an entity is created.
///
/// e.g.: ids
pub const CONSTANT: ConstantFieldBuilder<T, I, O, CtxOptions, ErrorTool> =
ConstantFieldBuilder::new();
/// A dependent field is one that belongs in the output struct O, but not in the input struct I.
///
/// This is a field that derives it values from one or more other fields.
///
/// A dependent field must:
/// - have a default value or a function to generate one
/// - one or more parent fields to react to
/// - a resolver (function) used to generate it's value, everytime the value of any of its parent fields
/// changes
pub const DEPENDENT: DependentFieldBuilder<T, I, O, CtxOptions, ErrorTool> =
DependentFieldBuilder::new();
/// Lax field
pub const LAX: LaxFieldBuilder<T, I, O, CtxOptions, ErrorTool> = LaxFieldBuilder::new();
/// Required field
pub const REQUIRED: RequiredFieldBuilder<T, I, O, CtxOptions, ErrorTool> =
RequiredFieldBuilder::new();
/// A virtual field is one that belongs in the input struct I, but not in the output struct O.
///
/// A virtual field must:
/// - be used in combination with dependent fields. i.e: a virtual field must be a parent to
/// one or more dependent fields
/// - have a validator
pub const VIRTUAL: VirtualFieldBuilder<T, I, O, CtxOptions, ErrorTool> =
VirtualFieldBuilder::new();
}