re_types/blueprint/components/
background_kind.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/blueprint/components/background_kind.fbs".
3
4#![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/// **Component**: The type of the background in a view.
23#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
24#[repr(u8)]
25pub enum BackgroundKind {
26    /// A dark gradient.
27    ///
28    /// In 3D views it changes depending on the direction of the view.
29    #[default]
30    GradientDark = 1,
31
32    /// A bright gradient.
33    ///
34    /// In 3D views it changes depending on the direction of the view.
35    GradientBright = 2,
36
37    /// Simple uniform color.
38    SolidColor = 3,
39}
40
41impl ::re_types_core::Component for BackgroundKind {
42    #[inline]
43    fn descriptor() -> ComponentDescriptor {
44        ComponentDescriptor::new("rerun.blueprint.components.BackgroundKind")
45    }
46}
47
48::re_types_core::macros::impl_into_cow!(BackgroundKind);
49
50impl ::re_types_core::Loggable for BackgroundKind {
51    #[inline]
52    fn arrow_datatype() -> arrow::datatypes::DataType {
53        #![allow(clippy::wildcard_imports)]
54        use arrow::datatypes::*;
55        DataType::UInt8
56    }
57
58    fn to_arrow_opt<'a>(
59        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
60    ) -> SerializationResult<arrow::array::ArrayRef>
61    where
62        Self: Clone + 'a,
63    {
64        #![allow(clippy::wildcard_imports)]
65        #![allow(clippy::manual_is_variant_and)]
66        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
67        use arrow::{array::*, buffer::*, datatypes::*};
68        Ok({
69            let (somes, data0): (Vec<_>, Vec<_>) = data
70                .into_iter()
71                .map(|datum| {
72                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
73                    let datum = datum.map(|datum| *datum as u8);
74                    (datum.is_some(), datum)
75                })
76                .unzip();
77            let data0_validity: Option<arrow::buffer::NullBuffer> = {
78                let any_nones = somes.iter().any(|some| !*some);
79                any_nones.then(|| somes.into())
80            };
81            as_array_ref(PrimitiveArray::<UInt8Type>::new(
82                ScalarBuffer::from(
83                    data0
84                        .into_iter()
85                        .map(|v| v.unwrap_or_default())
86                        .collect::<Vec<_>>(),
87                ),
88                data0_validity,
89            ))
90        })
91    }
92
93    fn from_arrow_opt(
94        arrow_data: &dyn arrow::array::Array,
95    ) -> DeserializationResult<Vec<Option<Self>>>
96    where
97        Self: Sized,
98    {
99        #![allow(clippy::wildcard_imports)]
100        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
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}