re_types/blueprint/components/
background_kind.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#![allow(non_camel_case_types)]
18
19use ::re_types_core::SerializationResult;
20use ::re_types_core::try_serialize_field;
21use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
22use ::re_types_core::{ComponentDescriptor, ComponentType};
23use ::re_types_core::{DeserializationError, DeserializationResult};
24
25#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
27#[repr(u8)]
28pub enum BackgroundKind {
29 #[default]
33 GradientDark = 1,
34
35 GradientBright = 2,
39
40 SolidColor = 3,
42}
43
44impl ::re_types_core::Component for BackgroundKind {
45 #[inline]
46 fn name() -> ComponentType {
47 "rerun.blueprint.components.BackgroundKind".into()
48 }
49}
50
51::re_types_core::macros::impl_into_cow!(BackgroundKind);
52
53impl ::re_types_core::Loggable for BackgroundKind {
54 #[inline]
55 fn arrow_datatype() -> arrow::datatypes::DataType {
56 use arrow::datatypes::*;
57 DataType::UInt8
58 }
59
60 fn to_arrow_opt<'a>(
61 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
62 ) -> SerializationResult<arrow::array::ArrayRef>
63 where
64 Self: Clone + 'a,
65 {
66 #![allow(clippy::manual_is_variant_and)]
67 use ::re_types_core::{Loggable as _, ResultExt as _, arrow_helpers::as_array_ref};
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 use ::re_types_core::{Loggable as _, ResultExt as _, arrow_zip_validity::ZipValidity};
101 use arrow::{array::*, buffer::*, datatypes::*};
102 Ok(arrow_data
103 .as_any()
104 .downcast_ref::<UInt8Array>()
105 .ok_or_else(|| {
106 let expected = Self::arrow_datatype();
107 let actual = arrow_data.data_type().clone();
108 DeserializationError::datatype_mismatch(expected, actual)
109 })
110 .with_context("rerun.blueprint.components.BackgroundKind#enum")?
111 .into_iter()
112 .map(|typ| match typ {
113 Some(1) => Ok(Some(Self::GradientDark)),
114 Some(2) => Ok(Some(Self::GradientBright)),
115 Some(3) => Ok(Some(Self::SolidColor)),
116 None => Ok(None),
117 Some(invalid) => Err(DeserializationError::missing_union_arm(
118 Self::arrow_datatype(),
119 "<invalid>",
120 invalid as _,
121 )),
122 })
123 .collect::<DeserializationResult<Vec<Option<_>>>>()
124 .with_context("rerun.blueprint.components.BackgroundKind")?)
125 }
126}
127
128impl std::fmt::Display for BackgroundKind {
129 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
130 match self {
131 Self::GradientDark => write!(f, "GradientDark"),
132 Self::GradientBright => write!(f, "GradientBright"),
133 Self::SolidColor => write!(f, "SolidColor"),
134 }
135 }
136}
137
138impl ::re_types_core::reflection::Enum for BackgroundKind {
139 #[inline]
140 fn variants() -> &'static [Self] {
141 &[Self::GradientDark, Self::GradientBright, Self::SolidColor]
142 }
143
144 #[inline]
145 fn docstring_md(self) -> &'static str {
146 match self {
147 Self::GradientDark => {
148 "A dark gradient.\n\nIn 3D views it changes depending on the direction of the view."
149 }
150 Self::GradientBright => {
151 "A bright gradient.\n\nIn 3D views it changes depending on the direction of the view."
152 }
153 Self::SolidColor => "Simple uniform color.",
154 }
155 }
156}
157
158impl ::re_byte_size::SizeBytes for BackgroundKind {
159 #[inline]
160 fn heap_size_bytes(&self) -> u64 {
161 0
162 }
163
164 #[inline]
165 fn is_pod() -> bool {
166 true
167 }
168}