re_types/archetypes/
text_log.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 ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Debug, PartialEq, Default)]
63pub struct TextLog {
64 pub text: Option<SerializedComponentBatch>,
66
67 pub level: Option<SerializedComponentBatch>,
71
72 pub color: Option<SerializedComponentBatch>,
74}
75
76impl TextLog {
77 #[inline]
81 pub fn descriptor_text() -> ComponentDescriptor {
82 ComponentDescriptor {
83 archetype: Some("rerun.archetypes.TextLog".into()),
84 component: "TextLog:text".into(),
85 component_type: Some("rerun.components.Text".into()),
86 }
87 }
88
89 #[inline]
93 pub fn descriptor_level() -> ComponentDescriptor {
94 ComponentDescriptor {
95 archetype: Some("rerun.archetypes.TextLog".into()),
96 component: "TextLog:level".into(),
97 component_type: Some("rerun.components.TextLogLevel".into()),
98 }
99 }
100
101 #[inline]
105 pub fn descriptor_color() -> ComponentDescriptor {
106 ComponentDescriptor {
107 archetype: Some("rerun.archetypes.TextLog".into()),
108 component: "TextLog:color".into(),
109 component_type: Some("rerun.components.Color".into()),
110 }
111 }
112}
113
114static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
115 once_cell::sync::Lazy::new(|| [TextLog::descriptor_text()]);
116
117static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
118 once_cell::sync::Lazy::new(|| [TextLog::descriptor_level()]);
119
120static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
121 once_cell::sync::Lazy::new(|| [TextLog::descriptor_color()]);
122
123static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
124 once_cell::sync::Lazy::new(|| {
125 [
126 TextLog::descriptor_text(),
127 TextLog::descriptor_level(),
128 TextLog::descriptor_color(),
129 ]
130 });
131
132impl TextLog {
133 pub const NUM_COMPONENTS: usize = 3usize;
135}
136
137impl ::re_types_core::Archetype for TextLog {
138 #[inline]
139 fn name() -> ::re_types_core::ArchetypeName {
140 "rerun.archetypes.TextLog".into()
141 }
142
143 #[inline]
144 fn display_name() -> &'static str {
145 "Text log"
146 }
147
148 #[inline]
149 fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
150 REQUIRED_COMPONENTS.as_slice().into()
151 }
152
153 #[inline]
154 fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
155 RECOMMENDED_COMPONENTS.as_slice().into()
156 }
157
158 #[inline]
159 fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
160 OPTIONAL_COMPONENTS.as_slice().into()
161 }
162
163 #[inline]
164 fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
165 ALL_COMPONENTS.as_slice().into()
166 }
167
168 #[inline]
169 fn from_arrow_components(
170 arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
171 ) -> DeserializationResult<Self> {
172 re_tracing::profile_function!();
173 use ::re_types_core::{Loggable as _, ResultExt as _};
174 let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
175 let text = arrays_by_descr
176 .get(&Self::descriptor_text())
177 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_text()));
178 let level = arrays_by_descr
179 .get(&Self::descriptor_level())
180 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_level()));
181 let color = arrays_by_descr
182 .get(&Self::descriptor_color())
183 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_color()));
184 Ok(Self { text, level, color })
185 }
186}
187
188impl ::re_types_core::AsComponents for TextLog {
189 #[inline]
190 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
191 use ::re_types_core::Archetype as _;
192 [self.text.clone(), self.level.clone(), self.color.clone()]
193 .into_iter()
194 .flatten()
195 .collect()
196 }
197}
198
199impl ::re_types_core::ArchetypeReflectionMarker for TextLog {}
200
201impl TextLog {
202 #[inline]
204 pub fn new(text: impl Into<crate::components::Text>) -> Self {
205 Self {
206 text: try_serialize_field(Self::descriptor_text(), [text]),
207 level: None,
208 color: None,
209 }
210 }
211
212 #[inline]
214 pub fn update_fields() -> Self {
215 Self::default()
216 }
217
218 #[inline]
220 pub fn clear_fields() -> Self {
221 use ::re_types_core::Loggable as _;
222 Self {
223 text: Some(SerializedComponentBatch::new(
224 crate::components::Text::arrow_empty(),
225 Self::descriptor_text(),
226 )),
227 level: Some(SerializedComponentBatch::new(
228 crate::components::TextLogLevel::arrow_empty(),
229 Self::descriptor_level(),
230 )),
231 color: Some(SerializedComponentBatch::new(
232 crate::components::Color::arrow_empty(),
233 Self::descriptor_color(),
234 )),
235 }
236 }
237
238 #[inline]
249 pub fn columns<I>(
250 self,
251 _lengths: I,
252 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
253 where
254 I: IntoIterator<Item = usize> + Clone,
255 {
256 let columns = [
257 self.text
258 .map(|text| text.partitioned(_lengths.clone()))
259 .transpose()?,
260 self.level
261 .map(|level| level.partitioned(_lengths.clone()))
262 .transpose()?,
263 self.color
264 .map(|color| color.partitioned(_lengths.clone()))
265 .transpose()?,
266 ];
267 Ok(columns.into_iter().flatten())
268 }
269
270 #[inline]
275 pub fn columns_of_unit_batches(
276 self,
277 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
278 let len_text = self.text.as_ref().map(|b| b.array.len());
279 let len_level = self.level.as_ref().map(|b| b.array.len());
280 let len_color = self.color.as_ref().map(|b| b.array.len());
281 let len = None.or(len_text).or(len_level).or(len_color).unwrap_or(0);
282 self.columns(std::iter::repeat(1).take(len))
283 }
284
285 #[inline]
287 pub fn with_text(mut self, text: impl Into<crate::components::Text>) -> Self {
288 self.text = try_serialize_field(Self::descriptor_text(), [text]);
289 self
290 }
291
292 #[inline]
297 pub fn with_many_text(
298 mut self,
299 text: impl IntoIterator<Item = impl Into<crate::components::Text>>,
300 ) -> Self {
301 self.text = try_serialize_field(Self::descriptor_text(), text);
302 self
303 }
304
305 #[inline]
309 pub fn with_level(mut self, level: impl Into<crate::components::TextLogLevel>) -> Self {
310 self.level = try_serialize_field(Self::descriptor_level(), [level]);
311 self
312 }
313
314 #[inline]
319 pub fn with_many_level(
320 mut self,
321 level: impl IntoIterator<Item = impl Into<crate::components::TextLogLevel>>,
322 ) -> Self {
323 self.level = try_serialize_field(Self::descriptor_level(), level);
324 self
325 }
326
327 #[inline]
329 pub fn with_color(mut self, color: impl Into<crate::components::Color>) -> Self {
330 self.color = try_serialize_field(Self::descriptor_color(), [color]);
331 self
332 }
333
334 #[inline]
339 pub fn with_many_color(
340 mut self,
341 color: impl IntoIterator<Item = impl Into<crate::components::Color>>,
342 ) -> Self {
343 self.color = try_serialize_field(Self::descriptor_color(), color);
344 self
345 }
346}
347
348impl ::re_byte_size::SizeBytes for TextLog {
349 #[inline]
350 fn heap_size_bytes(&self) -> u64 {
351 self.text.heap_size_bytes() + self.level.heap_size_bytes() + self.color.heap_size_bytes()
352 }
353}