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