1#[cfg(not(feature = "std"))]
4use alloc::{boxed::Box, vec::Vec};
5
6use crate::{Capability, FieldInfo, Kind, Sensitivity, TypeInfo, VariantInfo};
7
8#[derive(Debug)]
14pub struct ValueRef<'a> {
15 kind: Kind<'a>,
16 type_info: TypeInfo<'a>,
17 children: Option<Children<'a>>,
18 variant: Option<VariantInfo<'a>>,
19 sensitivity: Sensitivity,
20 capability: Capability,
21}
22
23impl<'a> ValueRef<'a> {
24 pub fn with_type(kind: Kind<'a>, type_info: TypeInfo<'a>) -> Self {
26 let capability = if kind.is_scalar() { Capability::INSPECT } else { Capability::READ_ALL };
27
28 Self {
29 kind,
30 type_info,
31 children: None,
32 variant: None,
33 sensitivity: Sensitivity::Normal,
34 capability,
35 }
36 }
37
38 pub fn with_children(kind: Kind<'a>, type_info: TypeInfo<'a>, children: Children<'a>) -> Self {
40 Self {
41 kind,
42 type_info,
43 children: Some(children),
44 variant: None,
45 sensitivity: Sensitivity::Normal,
46 capability: Capability::READ_ALL,
47 }
48 }
49
50 pub fn with_variant(mut self, variant: VariantInfo<'a>) -> Self {
52 self.variant = Some(variant);
53 self
54 }
55
56 pub fn with_sensitivity(mut self, sensitivity: Sensitivity) -> Self {
58 self.sensitivity = sensitivity;
59 self
60 }
61
62 pub fn kind(&self) -> &Kind<'a> {
64 &self.kind
65 }
66
67 pub fn type_info(&self) -> &TypeInfo<'a> {
69 &self.type_info
70 }
71
72 pub fn children(&self) -> Option<&Children<'a>> {
74 self.children.as_ref()
75 }
76
77 pub fn variant(&self) -> Option<&VariantInfo<'a>> {
79 self.variant.as_ref()
80 }
81
82 pub fn sensitivity(&self) -> Sensitivity {
84 self.sensitivity
85 }
86
87 pub fn capability(&self) -> Capability {
89 self.capability
90 }
91}
92
93#[derive(Debug)]
98pub enum Children<'a> {
99 Direct(Vec<(FieldInfo<'a>, ValueRef<'a>)>),
101}
102
103impl<'a> Children<'a> {
104 pub fn direct(fields: Vec<(FieldInfo<'a>, ValueRef<'a>)>) -> Self {
106 Self::Direct(fields)
107 }
108
109 pub fn len(&self) -> usize {
111 match self {
112 Children::Direct(fields) => fields.len(),
113 }
114 }
115
116 pub fn is_empty(&self) -> bool {
118 self.len() == 0
119 }
120}