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