From e3cca8a7f2b09b8b2298fec07ae800837fc023a8 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 5 Jul 2024 18:36:51 +0200 Subject: [PATCH] Forward to_arrow_opt for fully transparent types --- .../src/blueprint/components/active_tab.rs | 47 ++--------- .../blueprint/components/included_content.rs | 47 ++--------- .../src/blueprint/components/interactive.rs | 32 ++------ .../components/lock_range_during_zoom.rs | 32 ++------ .../blueprint/components/query_expression.rs | 47 ++--------- .../blueprint/components/space_view_class.rs | 47 ++--------- .../blueprint/components/space_view_origin.rs | 47 ++--------- .../tensor_dimension_index_slider.rs | 27 ++----- .../components/viewer_recommendation_hash.rs | 33 ++------ .../components/visible_time_range.rs | 27 ++----- .../blueprint/components/visual_bounds2d.rs | 27 ++----- crates/re_types/src/components/axis_length.rs | 33 ++------ crates/re_types/src/components/class_id.rs | 33 ++------ crates/re_types/src/components/color.rs | 33 ++------ crates/re_types/src/components/fill_ratio.rs | 33 ++------ .../src/components/gamma_correction.rs | 33 ++------ crates/re_types/src/components/half_size2d.rs | 52 ++---------- crates/re_types/src/components/half_size3d.rs | 52 ++---------- .../src/components/image_plane_distance.rs | 33 ++------ crates/re_types/src/components/keypoint_id.rs | 33 ++------ crates/re_types/src/components/material.rs | 27 ++----- crates/re_types/src/components/media_type.rs | 47 ++--------- crates/re_types/src/components/name.rs | 47 ++--------- crates/re_types/src/components/opacity.rs | 33 ++------ .../src/components/out_of_tree_transform3d.rs | 27 ++----- .../src/components/pinhole_projection.rs | 52 ++---------- crates/re_types/src/components/position2d.rs | 52 ++---------- crates/re_types/src/components/position3d.rs | 52 ++---------- crates/re_types/src/components/range1d.rs | 52 ++---------- crates/re_types/src/components/resolution.rs | 52 ++---------- crates/re_types/src/components/rotation3d.rs | 27 ++----- crates/re_types/src/components/tensor_data.rs | 27 ++----- .../tensor_dimension_index_selection.rs | 27 ++----- .../src/components/tensor_height_dimension.rs | 27 ++----- .../src/components/tensor_width_dimension.rs | 27 ++----- crates/re_types/src/components/texcoord2d.rs | 52 ++---------- crates/re_types/src/components/text.rs | 47 ++--------- .../re_types/src/components/text_log_level.rs | 47 ++--------- crates/re_types/src/components/transform3d.rs | 27 ++----- .../src/components/triangle_indices.rs | 52 ++---------- crates/re_types/src/components/vector2d.rs | 52 ++---------- crates/re_types/src/components/vector3d.rs | 52 ++---------- .../src/testing/components/affix_fuzzer1.rs | 27 ++----- .../src/testing/components/affix_fuzzer14.rs | 27 ++----- .../src/testing/components/affix_fuzzer19.rs | 27 ++----- .../src/testing/components/affix_fuzzer2.rs | 27 ++----- .../src/testing/components/affix_fuzzer20.rs | 27 ++----- .../src/testing/components/affix_fuzzer21.rs | 27 ++----- .../src/testing/components/affix_fuzzer3.rs | 27 ++----- .../components/included_space_view.rs | 52 ++---------- .../blueprint/components/root_container.rs | 52 ++---------- .../components/space_view_maximized.rs | 52 ++---------- .../re_types_builder/src/codegen/rust/api.rs | 79 +++++++++++++------ 53 files changed, 367 insertions(+), 1710 deletions(-) diff --git a/crates/re_types/src/blueprint/components/active_tab.rs b/crates/re_types/src/blueprint/components/active_tab.rs index a84210996aa0..b695b7ab7c00 100644 --- a/crates/re_types/src/blueprint/components/active_tab.rs +++ b/crates/re_types/src/blueprint/components/active_tab.rs @@ -89,53 +89,18 @@ impl ::re_types_core::Loggable for ActiveTab { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::EntityPath::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/included_content.rs b/crates/re_types/src/blueprint/components/included_content.rs index ce123c51e303..ac465a0fb56d 100644 --- a/crates/re_types/src/blueprint/components/included_content.rs +++ b/crates/re_types/src/blueprint/components/included_content.rs @@ -90,53 +90,18 @@ impl ::re_types_core::Loggable for IncludedContent { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::EntityPath::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/interactive.rs b/crates/re_types/src/blueprint/components/interactive.rs index 872dc26a4a32..7b0d1c80c4f3 100644 --- a/crates/re_types/src/blueprint/components/interactive.rs +++ b/crates/re_types/src/blueprint/components/interactive.rs @@ -87,38 +87,18 @@ impl ::re_types_core::Loggable for Interactive { DataType::Boolean } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - BooleanArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Bool::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs b/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs index 7277bf36a6e8..11b3ebe7743a 100644 --- a/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs +++ b/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs @@ -87,38 +87,18 @@ impl ::re_types_core::Loggable for LockRangeDuringZoom { DataType::Boolean } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - BooleanArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Bool::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/query_expression.rs b/crates/re_types/src/blueprint/components/query_expression.rs index 25d473d7ed4f..2daa00f1cbf8 100644 --- a/crates/re_types/src/blueprint/components/query_expression.rs +++ b/crates/re_types/src/blueprint/components/query_expression.rs @@ -94,53 +94,18 @@ impl ::re_types_core::Loggable for QueryExpression { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/space_view_class.rs b/crates/re_types/src/blueprint/components/space_view_class.rs index c25bca50d9e4..98f7fafcd382 100644 --- a/crates/re_types/src/blueprint/components/space_view_class.rs +++ b/crates/re_types/src/blueprint/components/space_view_class.rs @@ -85,53 +85,18 @@ impl ::re_types_core::Loggable for SpaceViewClass { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/space_view_origin.rs b/crates/re_types/src/blueprint/components/space_view_origin.rs index 2c8286ba0a68..ad0fcfdaff0f 100644 --- a/crates/re_types/src/blueprint/components/space_view_origin.rs +++ b/crates/re_types/src/blueprint/components/space_view_origin.rs @@ -85,53 +85,18 @@ impl ::re_types_core::Loggable for SpaceViewOrigin { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::EntityPath::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/tensor_dimension_index_slider.rs b/crates/re_types/src/blueprint/components/tensor_dimension_index_slider.rs index aca22c0c6432..965f260c74e0 100644 --- a/crates/re_types/src/blueprint/components/tensor_dimension_index_slider.rs +++ b/crates/re_types/src/blueprint/components/tensor_dimension_index_slider.rs @@ -93,33 +93,20 @@ impl ::re_types_core::Loggable for TensorDimensionIndexSlider { )])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) + crate::blueprint::datatypes::TensorDimensionIndexSlider::to_arrow_opt(data.into_iter().map( + |datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::blueprint::datatypes::TensorDimensionIndexSlider::to_arrow_opt(data0)? - } - }) + }, + )) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs b/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs index 849a51546e3f..1f90c8354e79 100644 --- a/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs +++ b/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs @@ -87,38 +87,18 @@ impl ::re_types_core::Loggable for ViewerRecommendationHash { DataType::UInt64 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::UInt64::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -132,7 +112,6 @@ impl ::re_types_core::Loggable for ViewerRecommendationHash { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/blueprint/components/visible_time_range.rs b/crates/re_types/src/blueprint/components/visible_time_range.rs index ce60f305248b..b4c61b0b68cf 100644 --- a/crates/re_types/src/blueprint/components/visible_time_range.rs +++ b/crates/re_types/src/blueprint/components/visible_time_range.rs @@ -98,33 +98,18 @@ impl ::re_types_core::Loggable for VisibleTimeRange { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::VisibleTimeRange::to_arrow_opt(data0)? - } - }) + crate::datatypes::VisibleTimeRange::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/blueprint/components/visual_bounds2d.rs b/crates/re_types/src/blueprint/components/visual_bounds2d.rs index 12fb7e7dbb60..e5f8181adc69 100644 --- a/crates/re_types/src/blueprint/components/visual_bounds2d.rs +++ b/crates/re_types/src/blueprint/components/visual_bounds2d.rs @@ -99,33 +99,18 @@ impl ::re_types_core::Loggable for VisualBounds2D { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::Range2D::to_arrow_opt(data0)? - } - }) + crate::datatypes::Range2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/axis_length.rs b/crates/re_types/src/components/axis_length.rs index e3767f7e2c1b..fd871f409d30 100644 --- a/crates/re_types/src/components/axis_length.rs +++ b/crates/re_types/src/components/axis_length.rs @@ -85,38 +85,18 @@ impl ::re_types_core::Loggable for AxisLength { DataType::Float32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -130,7 +110,6 @@ impl ::re_types_core::Loggable for AxisLength { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/class_id.rs b/crates/re_types/src/components/class_id.rs index 2086d4bc4ef9..0543df2b1b98 100644 --- a/crates/re_types/src/components/class_id.rs +++ b/crates/re_types/src/components/class_id.rs @@ -90,38 +90,18 @@ impl ::re_types_core::Loggable for ClassId { DataType::UInt16 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::ClassId::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -135,7 +115,6 @@ impl ::re_types_core::Loggable for ClassId { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/color.rs b/crates/re_types/src/components/color.rs index 88f4ad2c87eb..8e9cb9e1a015 100644 --- a/crates/re_types/src/components/color.rs +++ b/crates/re_types/src/components/color.rs @@ -88,38 +88,18 @@ impl ::re_types_core::Loggable for Color { DataType::UInt32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Rgba32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -133,7 +113,6 @@ impl ::re_types_core::Loggable for Color { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/fill_ratio.rs b/crates/re_types/src/components/fill_ratio.rs index a839f8c26ea5..1aa58663df2a 100644 --- a/crates/re_types/src/components/fill_ratio.rs +++ b/crates/re_types/src/components/fill_ratio.rs @@ -90,38 +90,18 @@ impl ::re_types_core::Loggable for FillRatio { DataType::Float32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -135,7 +115,6 @@ impl ::re_types_core::Loggable for FillRatio { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/gamma_correction.rs b/crates/re_types/src/components/gamma_correction.rs index 90e2d08aa99d..56603769351d 100644 --- a/crates/re_types/src/components/gamma_correction.rs +++ b/crates/re_types/src/components/gamma_correction.rs @@ -91,38 +91,18 @@ impl ::re_types_core::Loggable for GammaCorrection { DataType::Float32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -136,7 +116,6 @@ impl ::re_types_core::Loggable for GammaCorrection { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/half_size2d.rs b/crates/re_types/src/components/half_size2d.rs index 1291905064e1..152ddc4f188c 100644 --- a/crates/re_types/src/components/half_size2d.rs +++ b/crates/re_types/src/components/half_size2d.rs @@ -92,57 +92,18 @@ impl ::re_types_core::Loggable for HalfSize2D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -156,7 +117,6 @@ impl ::re_types_core::Loggable for HalfSize2D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/half_size3d.rs b/crates/re_types/src/components/half_size3d.rs index 5f207fcea40c..bffafc35a8b6 100644 --- a/crates/re_types/src/components/half_size3d.rs +++ b/crates/re_types/src/components/half_size3d.rs @@ -92,57 +92,18 @@ impl ::re_types_core::Loggable for HalfSize3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(3usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -156,7 +117,6 @@ impl ::re_types_core::Loggable for HalfSize3D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/image_plane_distance.rs b/crates/re_types/src/components/image_plane_distance.rs index a02858f0be5e..cdce1e0a4e56 100644 --- a/crates/re_types/src/components/image_plane_distance.rs +++ b/crates/re_types/src/components/image_plane_distance.rs @@ -86,38 +86,18 @@ impl ::re_types_core::Loggable for ImagePlaneDistance { DataType::Float32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -131,7 +111,6 @@ impl ::re_types_core::Loggable for ImagePlaneDistance { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/keypoint_id.rs b/crates/re_types/src/components/keypoint_id.rs index b2165da73efc..4224442076d6 100644 --- a/crates/re_types/src/components/keypoint_id.rs +++ b/crates/re_types/src/components/keypoint_id.rs @@ -102,38 +102,18 @@ impl ::re_types_core::Loggable for KeypointId { DataType::UInt16 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::KeypointId::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -147,7 +127,6 @@ impl ::re_types_core::Loggable for KeypointId { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/material.rs b/crates/re_types/src/components/material.rs index ed974e5b7481..5d1450cca63d 100644 --- a/crates/re_types/src/components/material.rs +++ b/crates/re_types/src/components/material.rs @@ -88,33 +88,18 @@ impl ::re_types_core::Loggable for Material { )])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::Material::to_arrow_opt(data0)? - } - }) + crate::datatypes::Material::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/media_type.rs b/crates/re_types/src/components/media_type.rs index 6b4e251be4e5..4f1731c7328f 100644 --- a/crates/re_types/src/components/media_type.rs +++ b/crates/re_types/src/components/media_type.rs @@ -88,53 +88,18 @@ impl ::re_types_core::Loggable for MediaType { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/name.rs b/crates/re_types/src/components/name.rs index ab50b31afd83..ba0d94c7e51b 100644 --- a/crates/re_types/src/components/name.rs +++ b/crates/re_types/src/components/name.rs @@ -85,53 +85,18 @@ impl ::re_types_core::Loggable for Name { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/opacity.rs b/crates/re_types/src/components/opacity.rs index 5459495d4820..8e17a2317620 100644 --- a/crates/re_types/src/components/opacity.rs +++ b/crates/re_types/src/components/opacity.rs @@ -88,38 +88,18 @@ impl ::re_types_core::Loggable for Opacity { DataType::Float32 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - Self::arrow_datatype(), - data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - data0_bitmap, - ) - .boxed() - }) + crate::datatypes::Float32::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -133,7 +113,6 @@ impl ::re_types_core::Loggable for Opacity { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/out_of_tree_transform3d.rs b/crates/re_types/src/components/out_of_tree_transform3d.rs index 557910e73c9a..aa4d1ab11591 100644 --- a/crates/re_types/src/components/out_of_tree_transform3d.rs +++ b/crates/re_types/src/components/out_of_tree_transform3d.rs @@ -105,33 +105,18 @@ impl ::re_types_core::Loggable for OutOfTreeTransform3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::Transform3D::to_arrow_opt(data0)? - } - }) + crate::datatypes::Transform3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/pinhole_projection.rs b/crates/re_types/src/components/pinhole_projection.rs index 021b9e31de4b..d3ac35f4b24a 100644 --- a/crates/re_types/src/components/pinhole_projection.rs +++ b/crates/re_types/src/components/pinhole_projection.rs @@ -97,57 +97,18 @@ impl ::re_types_core::Loggable for PinholeProjection { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(9usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Mat3x3::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -161,7 +122,6 @@ impl ::re_types_core::Loggable for PinholeProjection { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/position2d.rs b/crates/re_types/src/components/position2d.rs index 5037fa277951..1cf6a0360f7b 100644 --- a/crates/re_types/src/components/position2d.rs +++ b/crates/re_types/src/components/position2d.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for Position2D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for Position2D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/position3d.rs b/crates/re_types/src/components/position3d.rs index f94c053b7ff3..3cf36c998919 100644 --- a/crates/re_types/src/components/position3d.rs +++ b/crates/re_types/src/components/position3d.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for Position3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(3usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for Position3D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/range1d.rs b/crates/re_types/src/components/range1d.rs index 8e232e7609a1..8355f197894a 100644 --- a/crates/re_types/src/components/range1d.rs +++ b/crates/re_types/src/components/range1d.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for Range1D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float64, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Range1D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for Range1D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/resolution.rs b/crates/re_types/src/components/resolution.rs index 139170feb5b7..56cd8f2bc2de 100644 --- a/crates/re_types/src/components/resolution.rs +++ b/crates/re_types/src/components/resolution.rs @@ -89,57 +89,18 @@ impl ::re_types_core::Loggable for Resolution { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -153,7 +114,6 @@ impl ::re_types_core::Loggable for Resolution { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/rotation3d.rs b/crates/re_types/src/components/rotation3d.rs index a95f69b1ca7d..dfbe7b158fa5 100644 --- a/crates/re_types/src/components/rotation3d.rs +++ b/crates/re_types/src/components/rotation3d.rs @@ -103,33 +103,18 @@ impl ::re_types_core::Loggable for Rotation3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::Rotation3D::to_arrow_opt(data0)? - } - }) + crate::datatypes::Rotation3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/tensor_data.rs b/crates/re_types/src/components/tensor_data.rs index 228d60b15b40..9d7382391bb9 100644 --- a/crates/re_types/src/components/tensor_data.rs +++ b/crates/re_types/src/components/tensor_data.rs @@ -112,33 +112,18 @@ impl ::re_types_core::Loggable for TensorData { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::TensorData::to_arrow_opt(data0)? - } - }) + crate::datatypes::TensorData::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/tensor_dimension_index_selection.rs b/crates/re_types/src/components/tensor_dimension_index_selection.rs index 06b92255953c..fb19872be652 100644 --- a/crates/re_types/src/components/tensor_dimension_index_selection.rs +++ b/crates/re_types/src/components/tensor_dimension_index_selection.rs @@ -92,33 +92,20 @@ impl ::re_types_core::Loggable for TensorDimensionIndexSelection { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) + crate::datatypes::TensorDimensionIndexSelection::to_arrow_opt(data.into_iter().map( + |datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::TensorDimensionIndexSelection::to_arrow_opt(data0)? - } - }) + }, + )) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/tensor_height_dimension.rs b/crates/re_types/src/components/tensor_height_dimension.rs index 3db83ee87d73..4932bfddee82 100644 --- a/crates/re_types/src/components/tensor_height_dimension.rs +++ b/crates/re_types/src/components/tensor_height_dimension.rs @@ -88,33 +88,18 @@ impl ::re_types_core::Loggable for TensorHeightDimension { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::TensorDimensionSelection::to_arrow_opt(data0)? - } - }) + crate::datatypes::TensorDimensionSelection::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/tensor_width_dimension.rs b/crates/re_types/src/components/tensor_width_dimension.rs index c061bd1d09f8..0d52cc5cec4b 100644 --- a/crates/re_types/src/components/tensor_width_dimension.rs +++ b/crates/re_types/src/components/tensor_width_dimension.rs @@ -88,33 +88,18 @@ impl ::re_types_core::Loggable for TensorWidthDimension { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::TensorDimensionSelection::to_arrow_opt(data0)? - } - }) + crate::datatypes::TensorDimensionSelection::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/texcoord2d.rs b/crates/re_types/src/components/texcoord2d.rs index 74163e13c8ac..c9b8965cf61b 100644 --- a/crates/re_types/src/components/texcoord2d.rs +++ b/crates/re_types/src/components/texcoord2d.rs @@ -103,57 +103,18 @@ impl ::re_types_core::Loggable for Texcoord2D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -167,7 +128,6 @@ impl ::re_types_core::Loggable for Texcoord2D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/text.rs b/crates/re_types/src/components/text.rs index a4b94543f6eb..9c86d0a8b5cb 100644 --- a/crates/re_types/src/components/text.rs +++ b/crates/re_types/src/components/text.rs @@ -85,53 +85,18 @@ impl ::re_types_core::Loggable for Text { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/text_log_level.rs b/crates/re_types/src/components/text_log_level.rs index b0264a0d9fd6..a6d6790d1909 100644 --- a/crates/re_types/src/components/text_log_level.rs +++ b/crates/re_types/src/components/text_log_level.rs @@ -93,53 +93,18 @@ impl ::re_types_core::Loggable for TextLogLevel { DataType::Utf8 } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - let offsets = arrow2::offset::Offsets::::try_from_lengths( - data0 - .iter() - .map(|opt| opt.as_ref().map(|datum| datum.0.len()).unwrap_or_default()), - )? - .into(); - let inner_data: arrow2::buffer::Buffer = data0 - .into_iter() - .flatten() - .flat_map(|datum| datum.0 .0) - .collect(); - - #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)] - unsafe { - Utf8Array::::new_unchecked( - Self::arrow_datatype(), - offsets, - inner_data, - data0_bitmap, - ) - } - .boxed() - } - }) + crate::datatypes::Utf8::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/transform3d.rs b/crates/re_types/src/components/transform3d.rs index 35b74c18f2b7..3d1e7d5c25f4 100644 --- a/crates/re_types/src/components/transform3d.rs +++ b/crates/re_types/src/components/transform3d.rs @@ -103,33 +103,18 @@ impl ::re_types_core::Loggable for Transform3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::datatypes::Transform3D::to_arrow_opt(data0)? - } - }) + crate::datatypes::Transform3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/components/triangle_indices.rs b/crates/re_types/src/components/triangle_indices.rs index c8c6125375ed..d0726cea4f3d 100644 --- a/crates/re_types/src/components/triangle_indices.rs +++ b/crates/re_types/src/components/triangle_indices.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for TriangleIndices { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(3usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::UInt32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::UVec3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for TriangleIndices { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/vector2d.rs b/crates/re_types/src/components/vector2d.rs index 2835b4af7772..11ee206089c4 100644 --- a/crates/re_types/src/components/vector2d.rs +++ b/crates/re_types/src/components/vector2d.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for Vector2D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(2usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec2D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for Vector2D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/components/vector3d.rs b/crates/re_types/src/components/vector3d.rs index 2f96e3382d9e..35d449458451 100644 --- a/crates/re_types/src/components/vector3d.rs +++ b/crates/re_types/src/components/vector3d.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for Vector3D { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(3usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::Float32, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Vec3D::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for Vector3D { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types/src/testing/components/affix_fuzzer1.rs b/crates/re_types/src/testing/components/affix_fuzzer1.rs index 6e63950880b4..d7437b5fe80f 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer1.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer1.rs @@ -121,33 +121,18 @@ impl ::re_types_core::Loggable for AffixFuzzer1 { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer14.rs b/crates/re_types/src/testing/components/affix_fuzzer14.rs index 46eb63649e83..fd7269fb56a4 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer14.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer14.rs @@ -108,33 +108,18 @@ impl ::re_types_core::Loggable for AffixFuzzer14 { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer3::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer3::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer19.rs b/crates/re_types/src/testing/components/affix_fuzzer19.rs index 82f719010dc1..ea431b987e18 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer19.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer19.rs @@ -87,33 +87,18 @@ impl ::re_types_core::Loggable for AffixFuzzer19 { )])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer5::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer5::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer2.rs b/crates/re_types/src/testing/components/affix_fuzzer2.rs index 49561cd2e136..31835a4dcc49 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer2.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer2.rs @@ -121,33 +121,18 @@ impl ::re_types_core::Loggable for AffixFuzzer2 { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer20.rs b/crates/re_types/src/testing/components/affix_fuzzer20.rs index f8ce82092f22..e5e4a6744bf7 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer20.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer20.rs @@ -94,33 +94,18 @@ impl ::re_types_core::Loggable for AffixFuzzer20 { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer20::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer20::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer21.rs b/crates/re_types/src/testing/components/affix_fuzzer21.rs index fe0119fc0d2c..60d6abdafd84 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer21.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer21.rs @@ -94,33 +94,18 @@ impl ::re_types_core::Loggable for AffixFuzzer21 { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer21::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer21::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types/src/testing/components/affix_fuzzer3.rs b/crates/re_types/src/testing/components/affix_fuzzer3.rs index 3cf0258859df..5368bb3eacdc 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer3.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer3.rs @@ -121,33 +121,18 @@ impl ::re_types_core::Loggable for AffixFuzzer3 { ])) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - _ = data0_bitmap; - crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data0)? - } - }) + crate::testing::datatypes::AffixFuzzer1::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] diff --git a/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs b/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs index ef54550cb5da..39780a772ea8 100644 --- a/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs +++ b/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for IncludedSpaceView { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.bytes).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(16usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::UInt8, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Uuid::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for IncludedSpaceView { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types_blueprint/src/blueprint/components/root_container.rs b/crates/re_types_blueprint/src/blueprint/components/root_container.rs index 2588ea6ba7d2..49df858444a2 100644 --- a/crates/re_types_blueprint/src/blueprint/components/root_container.rs +++ b/crates/re_types_blueprint/src/blueprint/components/root_container.rs @@ -91,57 +91,18 @@ impl ::re_types_core::Loggable for RootContainer { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.bytes).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(16usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::UInt8, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Uuid::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -155,7 +116,6 @@ impl ::re_types_core::Loggable for RootContainer { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs b/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs index 4bb16932a290..a9c93fe410a5 100644 --- a/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs +++ b/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs @@ -88,57 +88,18 @@ impl ::re_types_core::Loggable for SpaceViewMaximized { ) } - #[allow(clippy::wildcard_imports)] fn to_arrow_opt<'a>( data: impl IntoIterator>>>, ) -> SerializationResult> where Self: Clone + 'a, { - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data0): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - let datum = datum.map(|datum| datum.into_owned().0); - (datum.is_some(), datum) - }) - .unzip(); - let data0_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - { - use arrow2::{buffer::Buffer, offset::OffsetsBuffer}; - let data0_inner_data: Vec<_> = data0 - .into_iter() - .map(|datum| datum.map(|datum| datum.bytes).unwrap_or_default()) - .flatten() - .collect(); - let data0_inner_bitmap: Option = - data0_bitmap.as_ref().map(|bitmap| { - bitmap - .iter() - .map(|b| std::iter::repeat(b).take(16usize)) - .flatten() - .collect::>() - .into() - }); - FixedSizeListArray::new( - Self::arrow_datatype(), - PrimitiveArray::new( - DataType::UInt8, - data0_inner_data.into_iter().collect(), - data0_inner_bitmap, - ) - .boxed(), - data0_bitmap, - ) - .boxed() - } - }) + crate::datatypes::Uuid::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) } #[allow(clippy::wildcard_imports)] @@ -152,7 +113,6 @@ impl ::re_types_core::Loggable for SpaceViewMaximized { .map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } - #[allow(clippy::wildcard_imports)] #[inline] fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> where diff --git a/crates/re_types_builder/src/codegen/rust/api.rs b/crates/re_types_builder/src/codegen/rust/api.rs index 62135eb920f9..e7ace82d0fc5 100644 --- a/crates/re_types_builder/src/codegen/rust/api.rs +++ b/crates/re_types_builder/src/codegen/rust/api.rs @@ -790,14 +790,13 @@ fn quote_trait_impls_from_obj( let datatype = ArrowDataTypeTokenizer(&datatype, false); - let forward_serialization = obj.is_arrow_transparent() + let forwarded_type = (obj.is_arrow_transparent() && !obj.fields[0].is_nullable - && matches!(obj.fields[0].typ, Type::Object(_)); + && matches!(obj.fields[0].typ, Type::Object(_))) + .then(|| quote_field_type_from_typ(&obj.fields[0].typ, true).0); let quoted_from_arrow = if optimize_for_buffer_slice { - let from_arrow_body = if forward_serialization { - let forwarded_type = quote_field_type_from_typ(&obj.fields[0].typ, true).0; - + let from_arrow_body = if let Some(forwarded_type) = forwarded_type.as_ref() { if obj .try_get_attr::(ATTR_RUST_DERIVE) .map_or(false, |d| d.contains("bytemuck::Pod")) @@ -835,8 +834,15 @@ fn quote_trait_impls_from_obj( Ok(#quoted_deserializer) } }; + + let allow_wildcard_import = if forwarded_type.is_some() { + quote!() + } else { + quote!(#[allow(clippy::wildcard_imports)]) + }; + quote! { - #[allow(clippy::wildcard_imports)] + #allow_wildcard_import #[inline] fn from_arrow( arrow_data: &dyn arrow2::array::Array, @@ -852,8 +858,7 @@ fn quote_trait_impls_from_obj( }; // Forward deserialization to existing datatype if it's transparent. - let quoted_deserializer = if forward_serialization { - let forwarded_type = quote_field_type_from_typ(&obj.fields[0].typ, true).0; + let quoted_deserializer = if let Some(forwarded_type) = forwarded_type.as_ref() { quote! { #forwarded_type::from_arrow_opt(arrow_data).map(|v| v.into_iter().map(|v| v.map(|v| Self(v))).collect()) } @@ -869,8 +874,45 @@ fn quote_trait_impls_from_obj( } }; - let quoted_serializer = - quote_arrow_serializer(arrow_registry, objects, obj, &format_ident!("data")); + let quoted_serializer = if let Some(forwarded_type) = forwarded_type.as_ref() { + quote! { + fn to_arrow_opt<'a>( + data: impl IntoIterator>>>, + ) -> SerializationResult> + where + Self: Clone + 'a, + { + #forwarded_type::to_arrow_opt(data.into_iter().map(|datum| { + datum.map(|datum| match datum.into() { + ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), + ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), + }) + })) + } + } + } else { + let quoted_serializer = + quote_arrow_serializer(arrow_registry, objects, obj, &format_ident!("data")); + + quote! { + // NOTE: Don't inline this, this gets _huge_. + #[allow(clippy::wildcard_imports)] + fn to_arrow_opt<'a>( + data: impl IntoIterator>>>, + ) -> SerializationResult> + where + Self: Clone + 'a + { + // NOTE(#3850): Don't add a profile scope here: the profiler overhead is too big for this fast function. + // re_tracing::profile_function!(); + + use arrow2::{datatypes::*, array::*}; + use ::re_types_core::{Loggable as _, ResultExt as _}; + + Ok(#quoted_serializer) + } + } + }; quote! { ::re_types_core::macros::impl_into_cow!(#name); @@ -890,22 +932,7 @@ fn quote_trait_impls_from_obj( #datatype } - // NOTE: Don't inline this, this gets _huge_. - #[allow(clippy::wildcard_imports)] - fn to_arrow_opt<'a>( - data: impl IntoIterator>>>, - ) -> SerializationResult> - where - Self: Clone + 'a - { - // NOTE(#3850): Don't add a profile scope here: the profiler overhead is too big for this fast function. - // re_tracing::profile_function!(); - - use arrow2::{datatypes::*, array::*}; - use ::re_types_core::{Loggable as _, ResultExt as _}; - - Ok(#quoted_serializer) - } + #quoted_serializer // NOTE: Don't inline this, this gets _huge_. #[allow(clippy::wildcard_imports)]