re_types/archetypes/
graph_edges.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)]
56pub struct GraphEdges {
57 pub edges: Option<SerializedComponentBatch>,
59
60 pub graph_type: Option<SerializedComponentBatch>,
64}
65
66impl GraphEdges {
67 #[inline]
71 pub fn descriptor_edges() -> ComponentDescriptor {
72 ComponentDescriptor {
73 archetype: Some("rerun.archetypes.GraphEdges".into()),
74 component: "GraphEdges:edges".into(),
75 component_type: Some("rerun.components.GraphEdge".into()),
76 }
77 }
78
79 #[inline]
83 pub fn descriptor_graph_type() -> ComponentDescriptor {
84 ComponentDescriptor {
85 archetype: Some("rerun.archetypes.GraphEdges".into()),
86 component: "GraphEdges:graph_type".into(),
87 component_type: Some("rerun.components.GraphType".into()),
88 }
89 }
90}
91
92static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
93 once_cell::sync::Lazy::new(|| [GraphEdges::descriptor_edges()]);
94
95static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
96 once_cell::sync::Lazy::new(|| [GraphEdges::descriptor_graph_type()]);
97
98static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
99 once_cell::sync::Lazy::new(|| []);
100
101static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 2usize]> =
102 once_cell::sync::Lazy::new(|| {
103 [
104 GraphEdges::descriptor_edges(),
105 GraphEdges::descriptor_graph_type(),
106 ]
107 });
108
109impl GraphEdges {
110 pub const NUM_COMPONENTS: usize = 2usize;
112}
113
114impl ::re_types_core::Archetype for GraphEdges {
115 #[inline]
116 fn name() -> ::re_types_core::ArchetypeName {
117 "rerun.archetypes.GraphEdges".into()
118 }
119
120 #[inline]
121 fn display_name() -> &'static str {
122 "Graph edges"
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 edges = arrays_by_descr
153 .get(&Self::descriptor_edges())
154 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_edges()));
155 let graph_type = arrays_by_descr
156 .get(&Self::descriptor_graph_type())
157 .map(|array| {
158 SerializedComponentBatch::new(array.clone(), Self::descriptor_graph_type())
159 });
160 Ok(Self { edges, graph_type })
161 }
162}
163
164impl ::re_types_core::AsComponents for GraphEdges {
165 #[inline]
166 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
167 use ::re_types_core::Archetype as _;
168 [self.edges.clone(), self.graph_type.clone()]
169 .into_iter()
170 .flatten()
171 .collect()
172 }
173}
174
175impl ::re_types_core::ArchetypeReflectionMarker for GraphEdges {}
176
177impl GraphEdges {
178 #[inline]
180 pub fn new(edges: impl IntoIterator<Item = impl Into<crate::components::GraphEdge>>) -> Self {
181 Self {
182 edges: try_serialize_field(Self::descriptor_edges(), edges),
183 graph_type: None,
184 }
185 }
186
187 #[inline]
189 pub fn update_fields() -> Self {
190 Self::default()
191 }
192
193 #[inline]
195 pub fn clear_fields() -> Self {
196 use ::re_types_core::Loggable as _;
197 Self {
198 edges: Some(SerializedComponentBatch::new(
199 crate::components::GraphEdge::arrow_empty(),
200 Self::descriptor_edges(),
201 )),
202 graph_type: Some(SerializedComponentBatch::new(
203 crate::components::GraphType::arrow_empty(),
204 Self::descriptor_graph_type(),
205 )),
206 }
207 }
208
209 #[inline]
220 pub fn columns<I>(
221 self,
222 _lengths: I,
223 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
224 where
225 I: IntoIterator<Item = usize> + Clone,
226 {
227 let columns = [
228 self.edges
229 .map(|edges| edges.partitioned(_lengths.clone()))
230 .transpose()?,
231 self.graph_type
232 .map(|graph_type| graph_type.partitioned(_lengths.clone()))
233 .transpose()?,
234 ];
235 Ok(columns.into_iter().flatten())
236 }
237
238 #[inline]
243 pub fn columns_of_unit_batches(
244 self,
245 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
246 let len_edges = self.edges.as_ref().map(|b| b.array.len());
247 let len_graph_type = self.graph_type.as_ref().map(|b| b.array.len());
248 let len = None.or(len_edges).or(len_graph_type).unwrap_or(0);
249 self.columns(std::iter::repeat(1).take(len))
250 }
251
252 #[inline]
254 pub fn with_edges(
255 mut self,
256 edges: impl IntoIterator<Item = impl Into<crate::components::GraphEdge>>,
257 ) -> Self {
258 self.edges = try_serialize_field(Self::descriptor_edges(), edges);
259 self
260 }
261
262 #[inline]
266 pub fn with_graph_type(mut self, graph_type: impl Into<crate::components::GraphType>) -> Self {
267 self.graph_type = try_serialize_field(Self::descriptor_graph_type(), [graph_type]);
268 self
269 }
270
271 #[inline]
276 pub fn with_many_graph_type(
277 mut self,
278 graph_type: impl IntoIterator<Item = impl Into<crate::components::GraphType>>,
279 ) -> Self {
280 self.graph_type = try_serialize_field(Self::descriptor_graph_type(), graph_type);
281 self
282 }
283}
284
285impl ::re_byte_size::SizeBytes for GraphEdges {
286 #[inline]
287 fn heap_size_bytes(&self) -> u64 {
288 self.edges.heap_size_bytes() + self.graph_type.heap_size_bytes()
289 }
290}