re_types_core/archetypes/
clear.rs1#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
15
16use crate::try_serialize_field;
17use crate::SerializationResult;
18use crate::{ComponentBatch as _, SerializedComponentBatch};
19use crate::{ComponentDescriptor, ComponentType};
20use crate::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Debug, PartialEq, Default)]
78pub struct Clear {
79 pub is_recursive: Option<SerializedComponentBatch>,
80}
81
82impl Clear {
83 #[inline]
87 pub fn descriptor_is_recursive() -> ComponentDescriptor {
88 ComponentDescriptor {
89 archetype: Some("rerun.archetypes.Clear".into()),
90 component: "Clear:is_recursive".into(),
91 component_type: Some("rerun.components.ClearIsRecursive".into()),
92 }
93 }
94}
95
96static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
97 once_cell::sync::Lazy::new(|| [Clear::descriptor_is_recursive()]);
98
99static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
100 once_cell::sync::Lazy::new(|| []);
101
102static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
103 once_cell::sync::Lazy::new(|| []);
104
105static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
106 once_cell::sync::Lazy::new(|| [Clear::descriptor_is_recursive()]);
107
108impl Clear {
109 pub const NUM_COMPONENTS: usize = 1usize;
111}
112
113impl crate::Archetype for Clear {
114 #[inline]
115 fn name() -> crate::ArchetypeName {
116 "rerun.archetypes.Clear".into()
117 }
118
119 #[inline]
120 fn display_name() -> &'static str {
121 "Clear"
122 }
123
124 #[inline]
125 fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
126 REQUIRED_COMPONENTS.as_slice().into()
127 }
128
129 #[inline]
130 fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
131 RECOMMENDED_COMPONENTS.as_slice().into()
132 }
133
134 #[inline]
135 fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
136 OPTIONAL_COMPONENTS.as_slice().into()
137 }
138
139 #[inline]
140 fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
141 ALL_COMPONENTS.as_slice().into()
142 }
143
144 #[inline]
145 fn from_arrow_components(
146 arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
147 ) -> DeserializationResult<Self> {
148 re_tracing::profile_function!();
149 use crate::{Loggable as _, ResultExt as _};
150 let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
151 let is_recursive = arrays_by_descr
152 .get(&Self::descriptor_is_recursive())
153 .map(|array| {
154 SerializedComponentBatch::new(array.clone(), Self::descriptor_is_recursive())
155 });
156 Ok(Self { is_recursive })
157 }
158}
159
160impl crate::AsComponents for Clear {
161 #[inline]
162 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
163 use crate::Archetype as _;
164 std::iter::once(self.is_recursive.clone())
165 .flatten()
166 .collect()
167 }
168}
169
170impl crate::ArchetypeReflectionMarker for Clear {}
171
172impl Clear {
173 #[inline]
175 pub fn new(is_recursive: impl Into<crate::components::ClearIsRecursive>) -> Self {
176 Self {
177 is_recursive: try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]),
178 }
179 }
180
181 #[inline]
183 pub fn update_fields() -> Self {
184 Self::default()
185 }
186
187 #[inline]
189 pub fn clear_fields() -> Self {
190 use crate::Loggable as _;
191 Self {
192 is_recursive: Some(SerializedComponentBatch::new(
193 crate::components::ClearIsRecursive::arrow_empty(),
194 Self::descriptor_is_recursive(),
195 )),
196 }
197 }
198
199 #[inline]
210 pub fn columns<I>(
211 self,
212 _lengths: I,
213 ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>>
214 where
215 I: IntoIterator<Item = usize> + Clone,
216 {
217 let columns = [self
218 .is_recursive
219 .map(|is_recursive| is_recursive.partitioned(_lengths.clone()))
220 .transpose()?];
221 Ok(columns.into_iter().flatten())
222 }
223
224 #[inline]
229 pub fn columns_of_unit_batches(
230 self,
231 ) -> SerializationResult<impl Iterator<Item = crate::SerializedComponentColumn>> {
232 let len_is_recursive = self.is_recursive.as_ref().map(|b| b.array.len());
233 let len = None.or(len_is_recursive).unwrap_or(0);
234 self.columns(std::iter::repeat(1).take(len))
235 }
236
237 #[inline]
238 pub fn with_is_recursive(
239 mut self,
240 is_recursive: impl Into<crate::components::ClearIsRecursive>,
241 ) -> Self {
242 self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), [is_recursive]);
243 self
244 }
245
246 #[inline]
251 pub fn with_many_is_recursive(
252 mut self,
253 is_recursive: impl IntoIterator<Item = impl Into<crate::components::ClearIsRecursive>>,
254 ) -> Self {
255 self.is_recursive = try_serialize_field(Self::descriptor_is_recursive(), is_recursive);
256 self
257 }
258}
259
260impl ::re_byte_size::SizeBytes for Clear {
261 #[inline]
262 fn heap_size_bytes(&self) -> u64 {
263 self.is_recursive.heap_size_bytes()
264 }
265}