re_types/blueprint/components/
background_kind.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#![allow(non_camel_case_types)]
16
17use ::re_types_core::try_serialize_field;
18use ::re_types_core::SerializationResult;
19use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
20use ::re_types_core::{ComponentDescriptor, ComponentType};
21use ::re_types_core::{DeserializationError, DeserializationResult};
22
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
25#[repr(u8)]
26pub enum BackgroundKind {
27 #[default]
31 GradientDark = 1,
32
33 GradientBright = 2,
37
38 SolidColor = 3,
40}
41
42impl ::re_types_core::Component for BackgroundKind {
43 #[inline]
44 fn name() -> ComponentType {
45 "rerun.blueprint.components.BackgroundKind".into()
46 }
47}
48
49::re_types_core::macros::impl_into_cow!(BackgroundKind);
50
51impl ::re_types_core::Loggable for BackgroundKind {
52 #[inline]
53 fn arrow_datatype() -> arrow::datatypes::DataType {
54 #![allow(clippy::wildcard_imports)]
55 use arrow::datatypes::*;
56 DataType::UInt8
57 }
58
59 fn to_arrow_opt<'a>(
60 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
61 ) -> SerializationResult<arrow::array::ArrayRef>
62 where
63 Self: Clone + 'a,
64 {
65 #![allow(clippy::wildcard_imports)]
66 #![allow(clippy::manual_is_variant_and)]
67 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
68 use arrow::{array::*, buffer::*, datatypes::*};
69 Ok({
70 let (somes, data0): (Vec<_>, Vec<_>) = data
71 .into_iter()
72 .map(|datum| {
73 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
74 let datum = datum.map(|datum| *datum as u8);
75 (datum.is_some(), datum)
76 })
77 .unzip();
78 let data0_validity: Option<arrow::buffer::NullBuffer> = {
79 let any_nones = somes.iter().any(|some| !*some);
80 any_nones.then(|| somes.into())
81 };
82 as_array_ref(PrimitiveArray::<UInt8Type>::new(
83 ScalarBuffer::from(
84 data0
85 .into_iter()
86 .map(|v| v.unwrap_or_default())
87 .collect::<Vec<_>>(),
88 ),
89 data0_validity,
90 ))
91 })
92 }
93
94 fn from_arrow_opt(
95 arrow_data: &dyn arrow::array::Array,
96 ) -> DeserializationResult<Vec<Option<Self>>>
97 where
98 Self: Sized,
99 {
100 #![allow(clippy::wildcard_imports)]
101 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
102 use arrow::{array::*, buffer::*, datatypes::*};
103 Ok(arrow_data
104 .as_any()
105 .downcast_ref::<UInt8Array>()
106 .ok_or_else(|| {
107 let expected = Self::arrow_datatype();
108 let actual = arrow_data.data_type().clone();
109 DeserializationError::datatype_mismatch(expected, actual)
110 })
111 .with_context("rerun.blueprint.components.BackgroundKind#enum")?
112 .into_iter()
113 .map(|typ| match typ {
114 Some(1) => Ok(Some(Self::GradientDark)),
115 Some(2) => Ok(Some(Self::GradientBright)),
116 Some(3) => Ok(Some(Self::SolidColor)),
117 None => Ok(None),
118 Some(invalid) => Err(DeserializationError::missing_union_arm(
119 Self::arrow_datatype(),
120 "<invalid>",
121 invalid as _,
122 )),
123 })
124 .collect::<DeserializationResult<Vec<Option<_>>>>()
125 .with_context("rerun.blueprint.components.BackgroundKind")?)
126 }
127}
128
129impl std::fmt::Display for BackgroundKind {
130 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
131 match self {
132 Self::GradientDark => write!(f, "GradientDark"),
133 Self::GradientBright => write!(f, "GradientBright"),
134 Self::SolidColor => write!(f, "SolidColor"),
135 }
136 }
137}
138
139impl ::re_types_core::reflection::Enum for BackgroundKind {
140 #[inline]
141 fn variants() -> &'static [Self] {
142 &[Self::GradientDark, Self::GradientBright, Self::SolidColor]
143 }
144
145 #[inline]
146 fn docstring_md(self) -> &'static str {
147 match self {
148 Self::GradientDark => {
149 "A dark gradient.\n\nIn 3D views it changes depending on the direction of the view."
150 }
151 Self::GradientBright => {
152 "A bright gradient.\n\nIn 3D views it changes depending on the direction of the view."
153 }
154 Self::SolidColor => "Simple uniform color.",
155 }
156 }
157}
158
159impl ::re_byte_size::SizeBytes for BackgroundKind {
160 #[inline]
161 fn heap_size_bytes(&self) -> u64 {
162 0
163 }
164
165 #[inline]
166 fn is_pod() -> bool {
167 true
168 }
169}