re_types/datatypes/
angle.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/angle.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**: Angle in radians.
22#[derive(Clone, Debug, Copy, Default, PartialEq, PartialOrd, bytemuck::Pod, bytemuck::Zeroable)]
23#[repr(transparent)]
24pub struct Angle {
25    /// Angle in radians. One turn is equal to 2π (or τ) radians.
26    pub radians: f32,
27}
28
29::re_types_core::macros::impl_into_cow!(Angle);
30
31impl ::re_types_core::Loggable for Angle {
32    #[inline]
33    fn arrow_datatype() -> arrow::datatypes::DataType {
34        #![allow(clippy::wildcard_imports)]
35        use arrow::datatypes::*;
36        DataType::Float32
37    }
38
39    fn to_arrow_opt<'a>(
40        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
41    ) -> SerializationResult<arrow::array::ArrayRef>
42    where
43        Self: Clone + 'a,
44    {
45        #![allow(clippy::wildcard_imports)]
46        #![allow(clippy::manual_is_variant_and)]
47        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
48        use arrow::{array::*, buffer::*, datatypes::*};
49        Ok({
50            let (somes, radians): (Vec<_>, Vec<_>) = data
51                .into_iter()
52                .map(|datum| {
53                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
54                    let datum = datum.map(|datum| datum.into_owned().radians);
55                    (datum.is_some(), datum)
56                })
57                .unzip();
58            let radians_validity: Option<arrow::buffer::NullBuffer> = {
59                let any_nones = somes.iter().any(|some| !*some);
60                any_nones.then(|| somes.into())
61            };
62            as_array_ref(PrimitiveArray::<Float32Type>::new(
63                ScalarBuffer::from(
64                    radians
65                        .into_iter()
66                        .map(|v| v.unwrap_or_default())
67                        .collect::<Vec<_>>(),
68                ),
69                radians_validity,
70            ))
71        })
72    }
73
74    fn from_arrow_opt(
75        arrow_data: &dyn arrow::array::Array,
76    ) -> DeserializationResult<Vec<Option<Self>>>
77    where
78        Self: Sized,
79    {
80        #![allow(clippy::wildcard_imports)]
81        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
82        use arrow::{array::*, buffer::*, datatypes::*};
83        Ok(arrow_data
84            .as_any()
85            .downcast_ref::<Float32Array>()
86            .ok_or_else(|| {
87                let expected = Self::arrow_datatype();
88                let actual = arrow_data.data_type().clone();
89                DeserializationError::datatype_mismatch(expected, actual)
90            })
91            .with_context("rerun.datatypes.Angle#radians")?
92            .into_iter()
93            .map(|v| v.ok_or_else(DeserializationError::missing_data))
94            .map(|res| res.map(|radians| Some(Self { radians })))
95            .collect::<DeserializationResult<Vec<Option<_>>>>()
96            .with_context("rerun.datatypes.Angle#radians")
97            .with_context("rerun.datatypes.Angle")?)
98    }
99
100    #[inline]
101    fn from_arrow(arrow_data: &dyn arrow::array::Array) -> DeserializationResult<Vec<Self>>
102    where
103        Self: Sized,
104    {
105        #![allow(clippy::wildcard_imports)]
106        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
107        use arrow::{array::*, buffer::*, datatypes::*};
108        if let Some(nulls) = arrow_data.nulls() {
109            if nulls.null_count() != 0 {
110                return Err(DeserializationError::missing_data());
111            }
112        }
113        Ok({
114            let slice = arrow_data
115                .as_any()
116                .downcast_ref::<Float32Array>()
117                .ok_or_else(|| {
118                    let expected = DataType::Float32;
119                    let actual = arrow_data.data_type().clone();
120                    DeserializationError::datatype_mismatch(expected, actual)
121                })
122                .with_context("rerun.datatypes.Angle#radians")?
123                .values()
124                .as_ref();
125            {
126                slice
127                    .iter()
128                    .copied()
129                    .map(|radians| Self { radians })
130                    .collect::<Vec<_>>()
131            }
132        })
133    }
134}
135
136impl From<f32> for Angle {
137    #[inline]
138    fn from(radians: f32) -> Self {
139        Self { radians }
140    }
141}
142
143impl From<Angle> for f32 {
144    #[inline]
145    fn from(value: Angle) -> Self {
146        value.radians
147    }
148}
149
150impl ::re_byte_size::SizeBytes for Angle {
151    #[inline]
152    fn heap_size_bytes(&self) -> u64 {
153        self.radians.heap_size_bytes()
154    }
155
156    #[inline]
157    fn is_pod() -> bool {
158        <f32>::is_pod()
159    }
160}