component_shape/
metadata.rs1use crate::ComponentSuffix;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum RenderCapability {
6 None,
8 Component,
10}
11
12impl RenderCapability {
13 pub const fn enabled(self) -> bool {
15 matches!(self, Self::Component)
16 }
17}
18
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21pub enum ValueBindingCapability {
22 None,
24 Inherited,
26}
27
28impl ValueBindingCapability {
29 pub const fn enabled(self) -> bool {
31 matches!(self, Self::Inherited)
32 }
33}
34
35#[derive(Clone, Copy, Debug, Eq, PartialEq)]
37pub struct ComponentCapabilities {
38 render: RenderCapability,
39 value_binding: ValueBindingCapability,
40}
41
42impl ComponentCapabilities {
43 pub const fn new() -> Self {
45 Self {
46 render: RenderCapability::None,
47 value_binding: ValueBindingCapability::None,
48 }
49 }
50
51 pub const fn with_render(mut self, render: RenderCapability) -> Self {
53 self.render = render;
54 self
55 }
56
57 pub const fn with_value_binding(mut self, value_binding: ValueBindingCapability) -> Self {
59 self.value_binding = value_binding;
60 self
61 }
62
63 pub const fn render(self) -> RenderCapability {
65 self.render
66 }
67
68 pub const fn value_binding(self) -> ValueBindingCapability {
70 self.value_binding
71 }
72
73 pub const fn render_component(self) -> bool {
75 self.render.enabled()
76 }
77
78 pub const fn value_binding_enabled(self) -> bool {
80 self.value_binding.enabled()
81 }
82}
83
84impl Default for ComponentCapabilities {
85 fn default() -> Self {
86 Self::new()
87 }
88}
89
90#[derive(Clone, Copy, Debug, Eq, PartialEq)]
92pub struct ComponentPrototyping {
93 pub field_suffix: Option<ComponentSuffix>,
95}
96
97impl ComponentPrototyping {
98 pub const fn new() -> Self {
100 Self { field_suffix: None }
101 }
102
103 pub const fn field_suffix(mut self, suffix: &'static str) -> Self {
109 self.field_suffix = Some(ComponentSuffix::new(suffix));
110 self
111 }
112}
113
114impl Default for ComponentPrototyping {
115 fn default() -> Self {
116 Self::new()
117 }
118}
119
120#[cfg(test)]
121mod tests {
122 use super::{
123 ComponentCapabilities, ComponentPrototyping, RenderCapability, ValueBindingCapability,
124 };
125
126 #[test]
127 fn component_capabilities_default_to_no_runtime_features() {
128 let capabilities = ComponentCapabilities::new();
129
130 assert_eq!(capabilities.render(), RenderCapability::None);
131 assert_eq!(capabilities.value_binding(), ValueBindingCapability::None);
132 assert!(!capabilities.render_component());
133 assert!(!capabilities.value_binding_enabled());
134 assert_eq!(ComponentCapabilities::default(), capabilities);
135 }
136
137 #[test]
138 fn component_capabilities_builders_set_independent_features() {
139 let capabilities = ComponentCapabilities::new()
140 .with_render(RenderCapability::Component)
141 .with_value_binding(ValueBindingCapability::Inherited);
142
143 assert_eq!(capabilities.render(), RenderCapability::Component);
144 assert_eq!(
145 capabilities.value_binding(),
146 ValueBindingCapability::Inherited
147 );
148 assert!(capabilities.render_component());
149 assert!(capabilities.value_binding_enabled());
150 }
151
152 #[test]
153 fn component_prototyping_field_suffix_records_suffix() {
154 let prototyping = ComponentPrototyping::new().field_suffix("input");
155
156 assert_eq!(
157 prototyping.field_suffix.map(crate::ComponentSuffix::as_str),
158 Some("input")
159 );
160 assert_eq!(ComponentPrototyping::default(), ComponentPrototyping::new());
161 }
162}