oo_bindgen/model/structs/
universal_struct.rs1use crate::model::*;
2
3#[non_exhaustive]
5#[derive(Clone, Debug)]
6pub enum UniversalStructField {
7    Basic(BasicType),
8    String(StringType),
9    Struct(UniversalStructHandle),
10}
11
12pub type UniversalStructHandle = Handle<Struct<UniversalStructField, Unvalidated>>;
13
14impl StructFieldType for UniversalStructField {
15    fn create_struct_type(
16        v: Handle<Struct<UniversalStructField, Unvalidated>>,
17    ) -> StructType<Unvalidated> {
18        StructType::Universal(v)
19    }
20}
21
22impl InitializerValidator for UniversalStructField {
23    fn validate_default_value(
24        &self,
25        value: &InitializerDefault,
26    ) -> BindResult<ValidatedDefaultValue> {
27        match self {
28            UniversalStructField::Basic(x) => x.validate_default_value(value),
29            UniversalStructField::Struct(x) => x.validate_default_value(value),
30            UniversalStructField::String(x) => x.validate_default_value(value),
31        }
32    }
33}
34
35impl From<Primitive> for UniversalStructField {
36    fn from(x: Primitive) -> Self {
37        Self::Basic(x.into())
38    }
39}
40
41impl From<BasicType> for UniversalStructField {
42    fn from(x: BasicType) -> Self {
43        UniversalStructField::Basic(x)
44    }
45}
46
47impl From<DurationType> for UniversalStructField {
48    fn from(x: DurationType) -> Self {
49        BasicType::Duration(x).into()
50    }
51}
52
53impl From<Handle<Enum<Unvalidated>>> for UniversalStructField {
54    fn from(x: Handle<Enum<Unvalidated>>) -> Self {
55        Self::Basic(BasicType::Enum(x))
56    }
57}
58
59impl From<UniversalStructHandle> for UniversalStructField {
60    fn from(x: UniversalStructHandle) -> Self {
61        UniversalStructField::Struct(x)
62    }
63}
64
65impl From<StringType> for UniversalStructField {
66    fn from(value: StringType) -> Self {
67        Self::String(value)
68    }
69}