re_types/components/
graph_type.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#![allow(non_camel_case_types)]
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, ComponentName};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
24#[repr(u8)]
25pub enum GraphType {
26 #[default]
28 Undirected = 1,
29
30 Directed = 2,
32}
33
34impl ::re_types_core::Component for GraphType {
35 #[inline]
36 fn descriptor() -> ComponentDescriptor {
37 ComponentDescriptor::new("rerun.components.GraphType")
38 }
39}
40
41::re_types_core::macros::impl_into_cow!(GraphType);
42
43impl ::re_types_core::Loggable for GraphType {
44 #[inline]
45 fn arrow_datatype() -> arrow::datatypes::DataType {
46 #![allow(clippy::wildcard_imports)]
47 use arrow::datatypes::*;
48 DataType::UInt8
49 }
50
51 fn to_arrow_opt<'a>(
52 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
53 ) -> SerializationResult<arrow::array::ArrayRef>
54 where
55 Self: Clone + 'a,
56 {
57 #![allow(clippy::wildcard_imports)]
58 #![allow(clippy::manual_is_variant_and)]
59 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
60 use arrow::{array::*, buffer::*, datatypes::*};
61 Ok({
62 let (somes, data0): (Vec<_>, Vec<_>) = data
63 .into_iter()
64 .map(|datum| {
65 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
66 let datum = datum.map(|datum| *datum as u8);
67 (datum.is_some(), datum)
68 })
69 .unzip();
70 let data0_validity: Option<arrow::buffer::NullBuffer> = {
71 let any_nones = somes.iter().any(|some| !*some);
72 any_nones.then(|| somes.into())
73 };
74 as_array_ref(PrimitiveArray::<UInt8Type>::new(
75 ScalarBuffer::from(
76 data0
77 .into_iter()
78 .map(|v| v.unwrap_or_default())
79 .collect::<Vec<_>>(),
80 ),
81 data0_validity,
82 ))
83 })
84 }
85
86 fn from_arrow_opt(
87 arrow_data: &dyn arrow::array::Array,
88 ) -> DeserializationResult<Vec<Option<Self>>>
89 where
90 Self: Sized,
91 {
92 #![allow(clippy::wildcard_imports)]
93 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
94 use arrow::{array::*, buffer::*, datatypes::*};
95 Ok(arrow_data
96 .as_any()
97 .downcast_ref::<UInt8Array>()
98 .ok_or_else(|| {
99 let expected = Self::arrow_datatype();
100 let actual = arrow_data.data_type().clone();
101 DeserializationError::datatype_mismatch(expected, actual)
102 })
103 .with_context("rerun.components.GraphType#enum")?
104 .into_iter()
105 .map(|typ| match typ {
106 Some(1) => Ok(Some(Self::Undirected)),
107 Some(2) => Ok(Some(Self::Directed)),
108 None => Ok(None),
109 Some(invalid) => Err(DeserializationError::missing_union_arm(
110 Self::arrow_datatype(),
111 "<invalid>",
112 invalid as _,
113 )),
114 })
115 .collect::<DeserializationResult<Vec<Option<_>>>>()
116 .with_context("rerun.components.GraphType")?)
117 }
118}
119
120impl std::fmt::Display for GraphType {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 match self {
123 Self::Undirected => write!(f, "Undirected"),
124 Self::Directed => write!(f, "Directed"),
125 }
126 }
127}
128
129impl ::re_types_core::reflection::Enum for GraphType {
130 #[inline]
131 fn variants() -> &'static [Self] {
132 &[Self::Undirected, Self::Directed]
133 }
134
135 #[inline]
136 fn docstring_md(self) -> &'static str {
137 match self {
138 Self::Undirected => "The graph has undirected edges.",
139 Self::Directed => "The graph has directed edges.",
140 }
141 }
142}
143
144impl ::re_byte_size::SizeBytes for GraphType {
145 #[inline]
146 fn heap_size_bytes(&self) -> u64 {
147 0
148 }
149
150 #[inline]
151 fn is_pod() -> bool {
152 true
153 }
154}