re_types/components/
geo_line_string.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/components/geo_line_string.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/// **Component**: A geospatial line string expressed in [EPSG:4326](https://epsg.io/4326) latitude and longitude (North/East-positive degrees).
22#[derive(Clone, Debug, Default, PartialEq)]
23#[repr(transparent)]
24pub struct GeoLineString(pub Vec<crate::datatypes::DVec2D>);
25
26impl ::re_types_core::Component for GeoLineString {
27    #[inline]
28    fn descriptor() -> ComponentDescriptor {
29        ComponentDescriptor::new("rerun.components.GeoLineString")
30    }
31}
32
33::re_types_core::macros::impl_into_cow!(GeoLineString);
34
35impl ::re_types_core::Loggable for GeoLineString {
36    #[inline]
37    fn arrow_datatype() -> arrow::datatypes::DataType {
38        #![allow(clippy::wildcard_imports)]
39        use arrow::datatypes::*;
40        DataType::List(std::sync::Arc::new(Field::new(
41            "item",
42            <crate::datatypes::DVec2D>::arrow_datatype(),
43            false,
44        )))
45    }
46
47    fn to_arrow_opt<'a>(
48        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
49    ) -> SerializationResult<arrow::array::ArrayRef>
50    where
51        Self: Clone + 'a,
52    {
53        #![allow(clippy::wildcard_imports)]
54        #![allow(clippy::manual_is_variant_and)]
55        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
56        use arrow::{array::*, buffer::*, datatypes::*};
57        Ok({
58            let (somes, data0): (Vec<_>, Vec<_>) = data
59                .into_iter()
60                .map(|datum| {
61                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
62                    let datum = datum.map(|datum| datum.into_owned().0);
63                    (datum.is_some(), datum)
64                })
65                .unzip();
66            let data0_validity: Option<arrow::buffer::NullBuffer> = {
67                let any_nones = somes.iter().any(|some| !*some);
68                any_nones.then(|| somes.into())
69            };
70            {
71                let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
72                    data0
73                        .iter()
74                        .map(|opt| opt.as_ref().map_or(0, |datum| datum.len())),
75                );
76                let data0_inner_data: Vec<_> = data0.into_iter().flatten().flatten().collect();
77                let data0_inner_validity: Option<arrow::buffer::NullBuffer> = None;
78                as_array_ref(ListArray::try_new(
79                    std::sync::Arc::new(Field::new(
80                        "item",
81                        <crate::datatypes::DVec2D>::arrow_datatype(),
82                        false,
83                    )),
84                    offsets,
85                    {
86                        let data0_inner_data_inner_data: Vec<_> = data0_inner_data
87                            .into_iter()
88                            .map(|datum| datum.0)
89                            .flatten()
90                            .collect();
91                        let data0_inner_data_inner_validity: Option<arrow::buffer::NullBuffer> =
92                            None;
93                        as_array_ref(FixedSizeListArray::new(
94                            std::sync::Arc::new(Field::new("item", DataType::Float64, false)),
95                            2,
96                            as_array_ref(PrimitiveArray::<Float64Type>::new(
97                                ScalarBuffer::from(
98                                    data0_inner_data_inner_data.into_iter().collect::<Vec<_>>(),
99                                ),
100                                data0_inner_data_inner_validity,
101                            )),
102                            data0_inner_validity,
103                        ))
104                    },
105                    data0_validity,
106                )?)
107            }
108        })
109    }
110
111    fn from_arrow_opt(
112        arrow_data: &dyn arrow::array::Array,
113    ) -> DeserializationResult<Vec<Option<Self>>>
114    where
115        Self: Sized,
116    {
117        #![allow(clippy::wildcard_imports)]
118        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
119        use arrow::{array::*, buffer::*, datatypes::*};
120        Ok({
121            let arrow_data = arrow_data
122                .as_any()
123                .downcast_ref::<arrow::array::ListArray>()
124                .ok_or_else(|| {
125                    let expected = Self::arrow_datatype();
126                    let actual = arrow_data.data_type().clone();
127                    DeserializationError::datatype_mismatch(expected, actual)
128                })
129                .with_context("rerun.components.GeoLineString#lat_lon")?;
130            if arrow_data.is_empty() {
131                Vec::new()
132            } else {
133                let arrow_data_inner = {
134                    let arrow_data_inner = &**arrow_data.values();
135                    {
136                        let arrow_data_inner = arrow_data_inner
137                            .as_any()
138                            .downcast_ref::<arrow::array::FixedSizeListArray>()
139                            .ok_or_else(|| {
140                                let expected = DataType::FixedSizeList(
141                                    std::sync::Arc::new(Field::new(
142                                        "item",
143                                        DataType::Float64,
144                                        false,
145                                    )),
146                                    2,
147                                );
148                                let actual = arrow_data_inner.data_type().clone();
149                                DeserializationError::datatype_mismatch(expected, actual)
150                            })
151                            .with_context("rerun.components.GeoLineString#lat_lon")?;
152                        if arrow_data_inner.is_empty() {
153                            Vec::new()
154                        } else {
155                            let offsets = (0..)
156                                .step_by(2usize)
157                                .zip((2usize..).step_by(2usize).take(arrow_data_inner.len()));
158                            let arrow_data_inner_inner = {
159                                let arrow_data_inner_inner = &**arrow_data_inner.values();
160                                arrow_data_inner_inner
161                                    .as_any()
162                                    .downcast_ref::<Float64Array>()
163                                    .ok_or_else(|| {
164                                        let expected = DataType::Float64;
165                                        let actual = arrow_data_inner_inner.data_type().clone();
166                                        DeserializationError::datatype_mismatch(expected, actual)
167                                    })
168                                    .with_context("rerun.components.GeoLineString#lat_lon")?
169                                    .into_iter()
170                                    .collect::<Vec<_>>()
171                            };
172                            ZipValidity::new_with_validity(offsets, arrow_data_inner.nulls())
173                                .map(|elem| {
174                                    elem.map(|(start, end): (usize, usize)| {
175                                        debug_assert!(end - start == 2usize);
176                                        if arrow_data_inner_inner.len() < end {
177                                            return Err(DeserializationError::offset_slice_oob(
178                                                (start, end),
179                                                arrow_data_inner_inner.len(),
180                                            ));
181                                        }
182
183                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
184                                        let data = unsafe {
185                                            arrow_data_inner_inner.get_unchecked(start..end)
186                                        };
187                                        let data =
188                                            data.iter().cloned().map(Option::unwrap_or_default);
189
190                                        // NOTE: Unwrapping cannot fail: the length must be correct.
191                                        #[allow(clippy::unwrap_used)]
192                                        Ok(array_init::from_iter(data).unwrap())
193                                    })
194                                    .transpose()
195                                })
196                                .map(|res_or_opt| {
197                                    res_or_opt
198                                        .map(|res_or_opt| res_or_opt.map(crate::datatypes::DVec2D))
199                                })
200                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
201                        }
202                        .into_iter()
203                    }
204                    .collect::<Vec<_>>()
205                };
206                let offsets = arrow_data.offsets();
207                ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
208                    .map(|elem| {
209                        elem.map(|window| {
210                            let start = window[0] as usize;
211                            let end = window[1] as usize;
212                            if arrow_data_inner.len() < end {
213                                return Err(DeserializationError::offset_slice_oob(
214                                    (start, end),
215                                    arrow_data_inner.len(),
216                                ));
217                            }
218
219                            #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
220                            let data = unsafe { arrow_data_inner.get_unchecked(start..end) };
221                            let data = data
222                                .iter()
223                                .cloned()
224                                .map(Option::unwrap_or_default)
225                                .collect();
226                            Ok(data)
227                        })
228                        .transpose()
229                    })
230                    .collect::<DeserializationResult<Vec<Option<_>>>>()?
231            }
232            .into_iter()
233        }
234        .map(|v| v.ok_or_else(DeserializationError::missing_data))
235        .map(|res| res.map(|v| Some(Self(v))))
236        .collect::<DeserializationResult<Vec<Option<_>>>>()
237        .with_context("rerun.components.GeoLineString#lat_lon")
238        .with_context("rerun.components.GeoLineString")?)
239    }
240}
241
242impl<I: Into<crate::datatypes::DVec2D>, T: IntoIterator<Item = I>> From<T> for GeoLineString {
243    fn from(v: T) -> Self {
244        Self(v.into_iter().map(|v| v.into()).collect())
245    }
246}
247
248impl ::re_byte_size::SizeBytes for GeoLineString {
249    #[inline]
250    fn heap_size_bytes(&self) -> u64 {
251        self.0.heap_size_bytes()
252    }
253
254    #[inline]
255    fn is_pod() -> bool {
256        <Vec<crate::datatypes::DVec2D>>::is_pod()
257    }
258}