re_types/blueprint/datatypes/
tensor_dimension_index_slider.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/datatypes/tensor_dimension_index_slider.fbs".
3
4#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
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, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22/// **Datatype**: Defines a slider for the index of some dimension.
23///
24/// ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
25#[derive(Clone, Debug, Default, Copy, Hash, PartialEq, Eq)]
26pub struct TensorDimensionIndexSlider {
27    /// The dimension number.
28    pub dimension: u32,
29}
30
31::re_types_core::macros::impl_into_cow!(TensorDimensionIndexSlider);
32
33impl ::re_types_core::Loggable for TensorDimensionIndexSlider {
34    #[inline]
35    fn arrow_datatype() -> arrow::datatypes::DataType {
36        #![allow(clippy::wildcard_imports)]
37        use arrow::datatypes::*;
38        DataType::Struct(Fields::from(vec![Field::new(
39            "dimension",
40            DataType::UInt32,
41            false,
42        )]))
43    }
44
45    fn to_arrow_opt<'a>(
46        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
47    ) -> SerializationResult<arrow::array::ArrayRef>
48    where
49        Self: Clone + 'a,
50    {
51        #![allow(clippy::wildcard_imports)]
52        #![allow(clippy::manual_is_variant_and)]
53        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
54        use arrow::{array::*, buffer::*, datatypes::*};
55        Ok({
56            let fields = Fields::from(vec![Field::new("dimension", DataType::UInt32, false)]);
57            let (somes, data): (Vec<_>, Vec<_>) = data
58                .into_iter()
59                .map(|datum| {
60                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
61                    (datum.is_some(), datum)
62                })
63                .unzip();
64            let validity: Option<arrow::buffer::NullBuffer> = {
65                let any_nones = somes.iter().any(|some| !*some);
66                any_nones.then(|| somes.into())
67            };
68            as_array_ref(StructArray::new(
69                fields,
70                vec![{
71                    let (somes, dimension): (Vec<_>, Vec<_>) = data
72                        .iter()
73                        .map(|datum| {
74                            let datum = datum.as_ref().map(|datum| datum.dimension.clone());
75                            (datum.is_some(), datum)
76                        })
77                        .unzip();
78                    let dimension_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::<UInt32Type>::new(
83                        ScalarBuffer::from(
84                            dimension
85                                .into_iter()
86                                .map(|v| v.unwrap_or_default())
87                                .collect::<Vec<_>>(),
88                        ),
89                        dimension_validity,
90                    ))
91                }],
92                validity,
93            ))
94        })
95    }
96
97    fn from_arrow_opt(
98        arrow_data: &dyn arrow::array::Array,
99    ) -> DeserializationResult<Vec<Option<Self>>>
100    where
101        Self: Sized,
102    {
103        #![allow(clippy::wildcard_imports)]
104        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
105        use arrow::{array::*, buffer::*, datatypes::*};
106        Ok({
107            let arrow_data = arrow_data
108                .as_any()
109                .downcast_ref::<arrow::array::StructArray>()
110                .ok_or_else(|| {
111                    let expected = Self::arrow_datatype();
112                    let actual = arrow_data.data_type().clone();
113                    DeserializationError::datatype_mismatch(expected, actual)
114                })
115                .with_context("rerun.blueprint.datatypes.TensorDimensionIndexSlider")?;
116            if arrow_data.is_empty() {
117                Vec::new()
118            } else {
119                let (arrow_data_fields, arrow_data_arrays) =
120                    (arrow_data.fields(), arrow_data.columns());
121                let arrays_by_name: ::std::collections::HashMap<_, _> = arrow_data_fields
122                    .iter()
123                    .map(|field| field.name().as_str())
124                    .zip(arrow_data_arrays)
125                    .collect();
126                let dimension = {
127                    if !arrays_by_name.contains_key("dimension") {
128                        return Err(DeserializationError::missing_struct_field(
129                            Self::arrow_datatype(),
130                            "dimension",
131                        ))
132                        .with_context("rerun.blueprint.datatypes.TensorDimensionIndexSlider");
133                    }
134                    let arrow_data = &**arrays_by_name["dimension"];
135                    arrow_data
136                        .as_any()
137                        .downcast_ref::<UInt32Array>()
138                        .ok_or_else(|| {
139                            let expected = DataType::UInt32;
140                            let actual = arrow_data.data_type().clone();
141                            DeserializationError::datatype_mismatch(expected, actual)
142                        })
143                        .with_context(
144                            "rerun.blueprint.datatypes.TensorDimensionIndexSlider#dimension",
145                        )?
146                        .into_iter()
147                };
148                ZipValidity::new_with_validity(
149                        ::itertools::izip!(dimension),
150                        arrow_data.nulls(),
151                    )
152                    .map(|opt| {
153                        opt
154                            .map(|(dimension)| Ok(Self {
155                                dimension: dimension
156                                    .ok_or_else(DeserializationError::missing_data)
157                                    .with_context(
158                                        "rerun.blueprint.datatypes.TensorDimensionIndexSlider#dimension",
159                                    )?,
160                            }))
161                            .transpose()
162                    })
163                    .collect::<DeserializationResult<Vec<_>>>()
164                    .with_context(
165                        "rerun.blueprint.datatypes.TensorDimensionIndexSlider",
166                    )?
167            }
168        })
169    }
170}
171
172impl From<u32> for TensorDimensionIndexSlider {
173    #[inline]
174    fn from(dimension: u32) -> Self {
175        Self { dimension }
176    }
177}
178
179impl From<TensorDimensionIndexSlider> for u32 {
180    #[inline]
181    fn from(value: TensorDimensionIndexSlider) -> Self {
182        value.dimension
183    }
184}
185
186impl ::re_byte_size::SizeBytes for TensorDimensionIndexSlider {
187    #[inline]
188    fn heap_size_bytes(&self) -> u64 {
189        self.dimension.heap_size_bytes()
190    }
191
192    #[inline]
193    fn is_pod() -> bool {
194        <u32>::is_pod()
195    }
196}