re_types/datatypes/
channel_datatype.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/channel_datatype.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/// **Datatype**: The innermost datatype of an image.
23///
24/// How individual color channel components are encoded.
25#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
26#[repr(u8)]
27pub enum ChannelDatatype {
28    /// 8-bit unsigned integer.
29    #[default]
30    U8 = 6,
31
32    /// 8-bit signed integer.
33    I8 = 7,
34
35    /// 16-bit unsigned integer.
36    U16 = 8,
37
38    /// 16-bit signed integer.
39    I16 = 9,
40
41    /// 32-bit unsigned integer.
42    U32 = 10,
43
44    /// 32-bit signed integer.
45    I32 = 11,
46
47    /// 64-bit unsigned integer.
48    U64 = 12,
49
50    /// 64-bit signed integer.
51    I64 = 13,
52
53    /// 16-bit IEEE-754 floating point, also known as `half`.
54    F16 = 33,
55
56    /// 32-bit IEEE-754 floating point, also known as `float` or `single`.
57    F32 = 34,
58
59    /// 64-bit IEEE-754 floating point, also known as `double`.
60    F64 = 35,
61}
62
63::re_types_core::macros::impl_into_cow!(ChannelDatatype);
64
65impl ::re_types_core::Loggable for ChannelDatatype {
66    #[inline]
67    fn arrow_datatype() -> arrow::datatypes::DataType {
68        #![allow(clippy::wildcard_imports)]
69        use arrow::datatypes::*;
70        DataType::UInt8
71    }
72
73    fn to_arrow_opt<'a>(
74        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
75    ) -> SerializationResult<arrow::array::ArrayRef>
76    where
77        Self: Clone + 'a,
78    {
79        #![allow(clippy::wildcard_imports)]
80        #![allow(clippy::manual_is_variant_and)]
81        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
82        use arrow::{array::*, buffer::*, datatypes::*};
83        Ok({
84            let (somes, data0): (Vec<_>, Vec<_>) = data
85                .into_iter()
86                .map(|datum| {
87                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
88                    let datum = datum.map(|datum| *datum as u8);
89                    (datum.is_some(), datum)
90                })
91                .unzip();
92            let data0_validity: Option<arrow::buffer::NullBuffer> = {
93                let any_nones = somes.iter().any(|some| !*some);
94                any_nones.then(|| somes.into())
95            };
96            as_array_ref(PrimitiveArray::<UInt8Type>::new(
97                ScalarBuffer::from(
98                    data0
99                        .into_iter()
100                        .map(|v| v.unwrap_or_default())
101                        .collect::<Vec<_>>(),
102                ),
103                data0_validity,
104            ))
105        })
106    }
107
108    fn from_arrow_opt(
109        arrow_data: &dyn arrow::array::Array,
110    ) -> DeserializationResult<Vec<Option<Self>>>
111    where
112        Self: Sized,
113    {
114        #![allow(clippy::wildcard_imports)]
115        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
116        use arrow::{array::*, buffer::*, datatypes::*};
117        Ok(arrow_data
118            .as_any()
119            .downcast_ref::<UInt8Array>()
120            .ok_or_else(|| {
121                let expected = Self::arrow_datatype();
122                let actual = arrow_data.data_type().clone();
123                DeserializationError::datatype_mismatch(expected, actual)
124            })
125            .with_context("rerun.datatypes.ChannelDatatype#enum")?
126            .into_iter()
127            .map(|typ| match typ {
128                Some(6) => Ok(Some(Self::U8)),
129                Some(7) => Ok(Some(Self::I8)),
130                Some(8) => Ok(Some(Self::U16)),
131                Some(9) => Ok(Some(Self::I16)),
132                Some(10) => Ok(Some(Self::U32)),
133                Some(11) => Ok(Some(Self::I32)),
134                Some(12) => Ok(Some(Self::U64)),
135                Some(13) => Ok(Some(Self::I64)),
136                Some(33) => Ok(Some(Self::F16)),
137                Some(34) => Ok(Some(Self::F32)),
138                Some(35) => Ok(Some(Self::F64)),
139                None => Ok(None),
140                Some(invalid) => Err(DeserializationError::missing_union_arm(
141                    Self::arrow_datatype(),
142                    "<invalid>",
143                    invalid as _,
144                )),
145            })
146            .collect::<DeserializationResult<Vec<Option<_>>>>()
147            .with_context("rerun.datatypes.ChannelDatatype")?)
148    }
149}
150
151impl std::fmt::Display for ChannelDatatype {
152    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
153        match self {
154            Self::U8 => write!(f, "U8"),
155            Self::I8 => write!(f, "I8"),
156            Self::U16 => write!(f, "U16"),
157            Self::I16 => write!(f, "I16"),
158            Self::U32 => write!(f, "U32"),
159            Self::I32 => write!(f, "I32"),
160            Self::U64 => write!(f, "U64"),
161            Self::I64 => write!(f, "I64"),
162            Self::F16 => write!(f, "F16"),
163            Self::F32 => write!(f, "F32"),
164            Self::F64 => write!(f, "F64"),
165        }
166    }
167}
168
169impl ::re_types_core::reflection::Enum for ChannelDatatype {
170    #[inline]
171    fn variants() -> &'static [Self] {
172        &[
173            Self::U8,
174            Self::I8,
175            Self::U16,
176            Self::I16,
177            Self::U32,
178            Self::I32,
179            Self::U64,
180            Self::I64,
181            Self::F16,
182            Self::F32,
183            Self::F64,
184        ]
185    }
186
187    #[inline]
188    fn docstring_md(self) -> &'static str {
189        match self {
190            Self::U8 => "8-bit unsigned integer.",
191            Self::I8 => "8-bit signed integer.",
192            Self::U16 => "16-bit unsigned integer.",
193            Self::I16 => "16-bit signed integer.",
194            Self::U32 => "32-bit unsigned integer.",
195            Self::I32 => "32-bit signed integer.",
196            Self::U64 => "64-bit unsigned integer.",
197            Self::I64 => "64-bit signed integer.",
198            Self::F16 => "16-bit IEEE-754 floating point, also known as `half`.",
199            Self::F32 => "32-bit IEEE-754 floating point, also known as `float` or `single`.",
200            Self::F64 => "64-bit IEEE-754 floating point, also known as `double`.",
201        }
202    }
203}
204
205impl ::re_byte_size::SizeBytes for ChannelDatatype {
206    #[inline]
207    fn heap_size_bytes(&self) -> u64 {
208        0
209    }
210
211    #[inline]
212    fn is_pod() -> bool {
213        true
214    }
215}