re_types/blueprint/components/
corner2d.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/corner2d.fbs".
3
4#![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/// **Component**: One of four 2D corners, typically used to align objects.
26#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
27#[repr(u8)]
28pub enum Corner2D {
29    /// Left top corner.
30    LeftTop = 1,
31
32    /// Right top corner.
33    RightTop = 2,
34
35    /// Left bottom corner.
36    #[default]
37    LeftBottom = 3,
38
39    /// Right bottom corner.
40    RightBottom = 4,
41}
42
43impl ::re_types_core::Component for Corner2D {
44    #[inline]
45    fn name() -> ComponentType {
46        "rerun.blueprint.components.Corner2D".into()
47    }
48}
49
50::re_types_core::macros::impl_into_cow!(Corner2D);
51
52impl ::re_types_core::Loggable for Corner2D {
53    #[inline]
54    fn arrow_datatype() -> arrow::datatypes::DataType {
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::manual_is_variant_and)]
66        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_helpers::as_array_ref};
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        use ::re_types_core::{Loggable as _, ResultExt as _, arrow_zip_validity::ZipValidity};
100        use arrow::{array::*, buffer::*, datatypes::*};
101        Ok(arrow_data
102            .as_any()
103            .downcast_ref::<UInt8Array>()
104            .ok_or_else(|| {
105                let expected = Self::arrow_datatype();
106                let actual = arrow_data.data_type().clone();
107                DeserializationError::datatype_mismatch(expected, actual)
108            })
109            .with_context("rerun.blueprint.components.Corner2D#enum")?
110            .into_iter()
111            .map(|typ| match typ {
112                Some(1) => Ok(Some(Self::LeftTop)),
113                Some(2) => Ok(Some(Self::RightTop)),
114                Some(3) => Ok(Some(Self::LeftBottom)),
115                Some(4) => Ok(Some(Self::RightBottom)),
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.Corner2D")?)
125    }
126}
127
128impl std::fmt::Display for Corner2D {
129    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
130        match self {
131            Self::LeftTop => write!(f, "LeftTop"),
132            Self::RightTop => write!(f, "RightTop"),
133            Self::LeftBottom => write!(f, "LeftBottom"),
134            Self::RightBottom => write!(f, "RightBottom"),
135        }
136    }
137}
138
139impl ::re_types_core::reflection::Enum for Corner2D {
140    #[inline]
141    fn variants() -> &'static [Self] {
142        &[
143            Self::LeftTop,
144            Self::RightTop,
145            Self::LeftBottom,
146            Self::RightBottom,
147        ]
148    }
149
150    #[inline]
151    fn docstring_md(self) -> &'static str {
152        match self {
153            Self::LeftTop => "Left top corner.",
154            Self::RightTop => "Right top corner.",
155            Self::LeftBottom => "Left bottom corner.",
156            Self::RightBottom => "Right bottom corner.",
157        }
158    }
159}
160
161impl ::re_byte_size::SizeBytes for Corner2D {
162    #[inline]
163    fn heap_size_bytes(&self) -> u64 {
164        0
165    }
166
167    #[inline]
168    fn is_pod() -> bool {
169        true
170    }
171}