diff --git a/crates/re_log_types/src/component_types/instance_key.rs b/crates/re_log_types/src/component_types/instance_key.rs index 4cddbad56db70..30d6b6b7893a7 100644 --- a/crates/re_log_types/src/component_types/instance_key.rs +++ b/crates/re_log_types/src/component_types/instance_key.rs @@ -36,6 +36,12 @@ impl InstanceKey { /// for example all points in a point cloud entity. pub const SPLAT: Self = Self(u64::MAX); + #[allow(clippy::should_implement_trait)] + #[inline] + pub fn from_iter(it: impl IntoIterator>) -> Vec { + it.into_iter().map(Into::into).collect::>() + } + /// Are we referring to all instances of the entity (e.g. all points in a point cloud entity)? /// /// The opposite of [`Self::is_specific`]. diff --git a/crates/re_query/src/entity_view.rs b/crates/re_query/src/entity_view.rs index a7f8c07c7d1f6..a9bf71e39f1a4 100644 --- a/crates/re_query/src/entity_view.rs +++ b/crates/re_query/src/entity_view.rs @@ -377,13 +377,7 @@ fn lookup_value() { use re_log_types::component_types::{InstanceKey, Point2D, Rect2D}; use re_log_types::external::arrow2_convert::serialize::arrow_serialize_to_mutable_array; - let instance_keys = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - InstanceKey(3), - InstanceKey(4), - ]; + let instance_keys = InstanceKey::from_iter(0..5); let points = [ Point2D { x: 1.0, y: 2.0 }, // diff --git a/crates/re_query/src/visit.rs b/crates/re_query/src/visit.rs index 1b9a314b0a3d8..86bdb178a179e 100644 --- a/crates/re_query/src/visit.rs +++ b/crates/re_query/src/visit.rs @@ -9,11 +9,7 @@ //! # use re_query::EntityView; //! # use re_log_types::component_types::{ColorRGBA, InstanceKey, Point2D}; //! -//! let instances = [ -//! InstanceKey(0), -//! InstanceKey(1), -//! InstanceKey(2), -//! ]; +//! let instances = InstanceKey::from_iter(0..3); //! //! let points = [ //! Point2D { x: 1.0, y: 2.0 }, diff --git a/crates/re_query/tests/visit_tests.rs b/crates/re_query/tests/visit_tests.rs index d9e56508eaa2e..7a401e95a2294 100644 --- a/crates/re_query/tests/visit_tests.rs +++ b/crates/re_query/tests/visit_tests.rs @@ -4,10 +4,7 @@ use re_query::{ComponentWithInstances, EntityView}; #[test] fn basic_single_iter() { - let instance_keys = [ - InstanceKey(0), // - InstanceKey(1), - ]; + let instance_keys = InstanceKey::from_iter(0..2); let points = [ Point2D { x: 1.0, y: 2.0 }, // Point2D { x: 3.0, y: 4.0 }, @@ -28,11 +25,7 @@ fn basic_single_iter() { #[test] fn implicit_joined_iter() { - let instance_keys = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - ]; + let instance_keys = InstanceKey::from_iter(0..3); let points = [ Point2D { x: 1.0, y: 2.0 }, // @@ -69,11 +62,7 @@ fn implicit_joined_iter() { #[test] fn implicit_primary_joined_iter() { - let point_ids = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - ]; + let point_ids = InstanceKey::from_iter(0..3); let points = [ Point2D { x: 1.0, y: 2.0 }, // @@ -126,13 +115,7 @@ fn implicit_component_joined_iter() { Point2D { x: 5.0, y: 6.0 }, ]; - let color_ids = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - InstanceKey(3), - InstanceKey(4), - ]; + let color_ids = InstanceKey::from_iter(0..5); let colors = [ ColorRGBA(0), // @@ -219,12 +202,7 @@ fn complex_joined_iter() { #[test] fn single_visit() { - let instance_keys = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - InstanceKey(3), - ]; + let instance_keys = InstanceKey::from_iter(0..4); let points = [ Point2D { x: 1.0, y: 2.0 }, Point2D { x: 3.0, y: 4.0 }, @@ -259,13 +237,7 @@ fn joint_visit() { Point2D { x: 9.0, y: 10.0 }, ]; - let point_ids = [ - InstanceKey(0), // - InstanceKey(1), - InstanceKey(2), - InstanceKey(3), - InstanceKey(4), - ]; + let point_ids = InstanceKey::from_iter(0..5); let colors = vec![ ColorRGBA(0xff000000), //