re_types_core/archetypes/
clear.rs1#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14
15use crate::try_serialize_field;
16use crate::SerializationResult;
17use crate::{ComponentBatch as _, SerializedComponentBatch};
18use crate::{ComponentDescriptor, ComponentName};
19use crate::{DeserializationError, DeserializationResult};
20
21#[derive(Clone, Debug, PartialEq, Default)]
77pub struct Clear {
78 pub is_recursive: Option<SerializedComponentBatch>,
79}
80
81impl Clear {
82 #[inline]
84 pub fn descriptor_is_recursive() -> ComponentDescriptor {
85 ComponentDescriptor {
86 archetype_name: Some("rerun.archetypes.Clear".into()),
87 component_name: "rerun.components.ClearIsRecursive".into(),
88 archetype_field_name: Some("is_recursive".into()),
89 }
90 }
91
92 #[inline]
94 pub fn descriptor_indicator() -> ComponentDescriptor {
95 ComponentDescriptor {
96 archetype_name: Some("rerun.archetypes.Clear".into()),
97 component_name: "rerun.components.ClearIndicator".into(),
98 archetype_field_name: None,
99 }
100 }
101}
102
103static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
104 once_cell::sync::Lazy::new(|| [Clear::descriptor_is_recursive()]);
105
106static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
107 once_cell::sync::Lazy::new(|| [Clear::descriptor_indicator()]);
108
109static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
110 once_cell::sync::Lazy::new(|| []);
111
112static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
113 once_cell::sync::Lazy::new(|| {
114 [
115 Clear::descriptor_is_recursive(),
116 Clear::descriptor_indicator(),
117 ]
118 });
119
120impl Clear {
121 pub const NUM_COMPONENTS: usize = 2usize;
123}
124
125pub type ClearIndicator = crate::GenericIndicatorComponent<Clear>;
127
128impl crate::Archetype for Clear {
129 type Indicator = ClearIndicator;
130
131 #[inline]
132 fn name() -> crate::ArchetypeName {
133 "rerun.archetypes.Clear".into()
134 }
135
136 #[inline]
137 fn display_name() -> &'static str {
138 "Clear"
139 }
140
141 #[inline]
142 fn indicator() -> SerializedComponentBatch {
143 #[allow(clippy::unwrap_used)]
144 ClearIndicator::DEFAULT.serialized().unwrap()
145 }
146
147 #[inline]
148 fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
149 REQUIRED_COMPONENTS.as_slice().into()
150 }
151
152 #[inline]
153 fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
154 RECOMMENDED_COMPONENTS.as_slice().into()
155 }
156
157 #[inline]
158 fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
159 OPTIONAL_COMPONENTS.as_slice().into()
160 }
161
162 #[inline]
163 fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
164 ALL_COMPONENTS.as_slice().into()
165 }
166
167 #[inline]
168 fn from_arrow_components(
169 arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
170 ) -> DeserializationResult<Self> {
171 re_tracing::profile_function!();
172 use crate::{Loggable as _, ResultExt as _};
173 let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
174 let is_recursive = arrays_by_descr
175 .get(&Self::descriptor_is_recursive())
176 .map(|array| {
177 SerializedComponentBatch::new(array.clone(), Self::descriptor_is_recursive())
178 });
179 Ok(Self { is_recursive })
180 }
181}
182
183impl crate::AsComponents for Clear {
184 #[inline]
185 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
186 use crate::Archetype as _;
187 [Some(Self::indicator()), self.is_recursive.clone()]
188 .into_iter()
189 .flatten()
190 .collect()
191 }
192}
193
194impl crate::ArchetypeReflectionMarker for Clear {}
195
196impl Clear {
197 #[inline]
199 pub fn new(is_recursive: impl Into<crate::components::ClearIsRecursive>) -> Self {
200 Self {
201 is_recursive: try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]),
202 }
203 }
204
205 #[inline]
207 pub fn update_fields() -> Self {
208 Self::default()
209 }
210
211 #[inline]
213 pub fn clear_fields() -> Self {
214 use crate::Loggable as _;
215 Self {
216 is_recursive: Some(SerializedComponentBatch::new(
217 crate::components::ClearIsRecursive::arrow_empty(),
218 Self::descriptor_is_recursive(),
219 )),
220 }
221 }
222
223 #[inline]
234 pub fn columns<I>(
235 self,
236 _lengths: I,
237 ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>>
238 where
239 I: IntoIterator<Item = usize> + Clone,
240 {
241 let columns = [self
242 .is_recursive
243 .map(|is_recursive| is_recursive.partitioned(_lengths.clone()))
244 .transpose()?];
245 Ok(columns
246 .into_iter()
247 .flatten()
248 .chain([crate::indicator_column::<Self>(
249 _lengths.into_iter().count(),
250 )?]))
251 }
252
253 #[inline]
258 pub fn columns_of_unit_batches(
259 self,
260 ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>> {
261 let len_is_recursive = self.is_recursive.as_ref().map(|b| b.array.len());
262 let len = None.or(len_is_recursive).unwrap_or(0);
263 self.columns(std::iter::repeat(1).take(len))
264 }
265
266 #[inline]
267 pub fn with_is_recursive(
268 mut self,
269 is_recursive: impl Into<crate::components::ClearIsRecursive>,
270 ) -> Self {
271 self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]);
272 self
273 }
274
275 #[inline]
280 pub fn with_many_is_recursive(
281 mut self,
282 is_recursive: impl IntoIterator<Item = impl Into<crate::components::ClearIsRecursive>>,
283 ) -> Self {
284 self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), is_recursive);
285 self
286 }
287}
288
289impl ::re_byte_size::SizeBytes for Clear {
290 #[inline]
291 fn heap_size_bytes(&self) -> u64 {
292 self.is_recursive.heap_size_bytes()
293 }
294}