re_types/datatypes/
keypoint_id.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/datatypes/keypoint_id.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
15use ::re_types_core::try_serialize_field;
16use ::re_types_core::SerializationResult;
17use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
18use ::re_types_core::{ComponentDescriptor, ComponentName};
19use ::re_types_core::{DeserializationError, DeserializationResult};
20
21/// **Datatype**: A 16-bit ID representing a type of semantic keypoint within a class.
22///
23/// `KeypointId`s are only meaningful within the context of a [`crate::datatypes::ClassDescription`].
24///
25/// Used to look up an [`crate::datatypes::AnnotationInfo`] for a Keypoint within the [`crate::components::AnnotationContext`].
26#[derive(
27    Clone,
28    Debug,
29    Copy,
30    Default,
31    PartialEq,
32    Eq,
33    PartialOrd,
34    Ord,
35    Hash,
36    bytemuck::Pod,
37    bytemuck::Zeroable,
38)]
39#[repr(transparent)]
40#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
41pub struct KeypointId(pub u16);
42
43::re_types_core::macros::impl_into_cow!(KeypointId);
44
45impl ::re_types_core::Loggable for KeypointId {
46    #[inline]
47    fn arrow_datatype() -> arrow::datatypes::DataType {
48        #![allow(clippy::wildcard_imports)]
49        use arrow::datatypes::*;
50        DataType::UInt16
51    }
52
53    fn to_arrow_opt<'a>(
54        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
55    ) -> SerializationResult<arrow::array::ArrayRef>
56    where
57        Self: Clone + 'a,
58    {
59        #![allow(clippy::wildcard_imports)]
60        #![allow(clippy::manual_is_variant_and)]
61        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
62        use arrow::{array::*, buffer::*, datatypes::*};
63        Ok({
64            let (somes, data0): (Vec<_>, Vec<_>) = data
65                .into_iter()
66                .map(|datum| {
67                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
68                    let datum = datum.map(|datum| datum.into_owned().0);
69                    (datum.is_some(), datum)
70                })
71                .unzip();
72            let data0_validity: Option<arrow::buffer::NullBuffer> = {
73                let any_nones = somes.iter().any(|some| !*some);
74                any_nones.then(|| somes.into())
75            };
76            as_array_ref(PrimitiveArray::<UInt16Type>::new(
77                ScalarBuffer::from(
78                    data0
79                        .into_iter()
80                        .map(|v| v.unwrap_or_default())
81                        .collect::<Vec<_>>(),
82                ),
83                data0_validity,
84            ))
85        })
86    }
87
88    fn from_arrow_opt(
89        arrow_data: &dyn arrow::array::Array,
90    ) -> DeserializationResult<Vec<Option<Self>>>
91    where
92        Self: Sized,
93    {
94        #![allow(clippy::wildcard_imports)]
95        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
96        use arrow::{array::*, buffer::*, datatypes::*};
97        Ok(arrow_data
98            .as_any()
99            .downcast_ref::<UInt16Array>()
100            .ok_or_else(|| {
101                let expected = Self::arrow_datatype();
102                let actual = arrow_data.data_type().clone();
103                DeserializationError::datatype_mismatch(expected, actual)
104            })
105            .with_context("rerun.datatypes.KeypointId#id")?
106            .into_iter()
107            .map(|v| v.ok_or_else(DeserializationError::missing_data))
108            .map(|res| res.map(|v| Some(Self(v))))
109            .collect::<DeserializationResult<Vec<Option<_>>>>()
110            .with_context("rerun.datatypes.KeypointId#id")
111            .with_context("rerun.datatypes.KeypointId")?)
112    }
113
114    #[inline]
115    fn from_arrow(arrow_data: &dyn arrow::array::Array) -> DeserializationResult<Vec<Self>>
116    where
117        Self: Sized,
118    {
119        #![allow(clippy::wildcard_imports)]
120        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
121        use arrow::{array::*, buffer::*, datatypes::*};
122        if let Some(nulls) = arrow_data.nulls() {
123            if nulls.null_count() != 0 {
124                return Err(DeserializationError::missing_data());
125            }
126        }
127        Ok({
128            let slice = arrow_data
129                .as_any()
130                .downcast_ref::<UInt16Array>()
131                .ok_or_else(|| {
132                    let expected = DataType::UInt16;
133                    let actual = arrow_data.data_type().clone();
134                    DeserializationError::datatype_mismatch(expected, actual)
135                })
136                .with_context("rerun.datatypes.KeypointId#id")?
137                .values()
138                .as_ref();
139            {
140                slice.iter().copied().map(Self).collect::<Vec<_>>()
141            }
142        })
143    }
144}
145
146impl From<u16> for KeypointId {
147    #[inline]
148    fn from(id: u16) -> Self {
149        Self(id)
150    }
151}
152
153impl From<KeypointId> for u16 {
154    #[inline]
155    fn from(value: KeypointId) -> Self {
156        value.0
157    }
158}
159
160impl ::re_byte_size::SizeBytes for KeypointId {
161    #[inline]
162    fn heap_size_bytes(&self) -> u64 {
163        self.0.heap_size_bytes()
164    }
165
166    #[inline]
167    fn is_pod() -> bool {
168        <u16>::is_pod()
169    }
170}