Skip to content

Commit 1cc6244

Browse files
oxkitsuneWumpf
andauthored
Allow logging individual components directly (Impl AsComponents for all ObjectKind::Component) (#7756)
<!-- Open the PR up as a draft until you feel it is ready for a proper review. Do not make PR:s from your own `main` branch, as that makes it difficult for reviewers to add their own fixes. Add any improvements to the branch as new commits to make it easier for reviewers to follow the progress. All commits will be squashed to a single commit once the PR is merged into `main`. Make sure you mention any issues that this PR closes in the description, as well as any other related issues. To get an auto-generated PR description you can put "copilot:summary" or "copilot:walkthrough" anywhere. --> ### What This implements `AsComponents` for all `Component`s, which makes the rust api slightly more ergonomic and makes this possible: ```rs rec.log_static("my_points", &rerun::Color::from_rgb(128, 128, 128))?; ``` ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7756?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7756?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7756) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. --------- Co-authored-by: Andreas Reich <[email protected]>
1 parent 9773d8a commit 1cc6244

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

crates/store/re_types_core/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ pub trait AsComponents {
8282
}
8383
}
8484

85+
impl<C: Component> AsComponents for C {
86+
#[inline]
87+
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
88+
vec![(self as &dyn ComponentBatch).into()]
89+
}
90+
}
91+
8592
// ---
8693

8794
mod archetype;

crates/top/re_sdk/src/recording_stream.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ impl RecordingStream {
856856
/// Log data to Rerun.
857857
///
858858
/// This is the main entry point for logging data to rerun. It can be used to log anything
859-
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html).
859+
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html)
860+
/// or individual [component](https://docs.rs/rerun/latest/rerun/components/index.html).
860861
///
861862
/// The data will be timestamped automatically based on the [`RecordingStream`]'s internal clock.
862863
/// See [`RecordingStream::set_time_sequence`] etc for more information.
@@ -889,9 +890,9 @@ impl RecordingStream {
889890
pub fn log(
890891
&self,
891892
ent_path: impl Into<EntityPath>,
892-
arch: &impl AsComponents,
893+
as_components: &impl AsComponents,
893894
) -> RecordingStreamResult<()> {
894-
self.log_with_static(ent_path, false, arch)
895+
self.log_with_static(ent_path, false, as_components)
895896
}
896897

897898
/// Lower-level logging API to provide data spanning multiple timepoints.
@@ -951,7 +952,8 @@ impl RecordingStream {
951952
/// Log data to Rerun.
952953
///
953954
/// It can be used to log anything
954-
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html).
955+
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html)
956+
/// or individual [component](https://docs.rs/rerun/latest/rerun/components/index.html).
955957
///
956958
/// Static data has no time associated with it, exists on all timelines, and unconditionally shadows
957959
/// any temporal data of the same type.
@@ -972,9 +974,9 @@ impl RecordingStream {
972974
pub fn log_static(
973975
&self,
974976
ent_path: impl Into<EntityPath>,
975-
arch: &impl AsComponents,
977+
as_components: &impl AsComponents,
976978
) -> RecordingStreamResult<()> {
977-
self.log_with_static(ent_path, true, arch)
979+
self.log_with_static(ent_path, true, as_components)
978980
}
979981

980982
#[deprecated(since = "0.16.0", note = "use `log_static` instead")]
@@ -1016,14 +1018,15 @@ impl RecordingStream {
10161018
&self,
10171019
ent_path: impl Into<EntityPath>,
10181020
static_: bool,
1019-
arch: &impl AsComponents,
1021+
as_components: &impl AsComponents,
10201022
) -> RecordingStreamResult<()> {
10211023
let row_id = RowId::new(); // Create row-id as early as possible. It has a timestamp and is used to estimate e2e latency.
10221024
self.log_component_batches_impl(
10231025
row_id,
10241026
ent_path,
10251027
static_,
1026-
arch.as_component_batches()
1028+
as_components
1029+
.as_component_batches()
10271030
.iter()
10281031
.map(|any_comp_batch| any_comp_batch.as_ref()),
10291032
)
@@ -2448,16 +2451,20 @@ mod tests {
24482451
components: [
24492452
(
24502453
MyPoint::name(),
2451-
MyPoint::to_arrow([MyPoint::new(10.0, 10.0), MyPoint::new(20.0, 20.0)])
2452-
.unwrap(),
2454+
<MyPoint as re_types_core::Loggable>::to_arrow([
2455+
MyPoint::new(10.0, 10.0),
2456+
MyPoint::new(20.0, 20.0),
2457+
])
2458+
.unwrap(),
24532459
), //
24542460
(
24552461
MyColor::name(),
2456-
MyColor::to_arrow([MyColor(0x8080_80FF)]).unwrap(),
2462+
<MyColor as re_types_core::Loggable>::to_arrow([MyColor(0x8080_80FF)])
2463+
.unwrap(),
24572464
), //
24582465
(
24592466
MyLabel::name(),
2460-
MyLabel::to_arrow([] as [MyLabel; 0]).unwrap(),
2467+
<MyLabel as re_types_core::Loggable>::to_arrow([] as [MyLabel; 0]).unwrap(),
24612468
), //
24622469
]
24632470
.into_iter()
@@ -2472,15 +2479,15 @@ mod tests {
24722479
components: [
24732480
(
24742481
MyPoint::name(),
2475-
MyPoint::to_arrow([] as [MyPoint; 0]).unwrap(),
2482+
<MyPoint as re_types_core::Loggable>::to_arrow([] as [MyPoint; 0]).unwrap(),
24762483
), //
24772484
(
24782485
MyColor::name(),
2479-
MyColor::to_arrow([] as [MyColor; 0]).unwrap(),
2486+
<MyColor as re_types_core::Loggable>::to_arrow([] as [MyColor; 0]).unwrap(),
24802487
), //
24812488
(
24822489
MyLabel::name(),
2483-
MyLabel::to_arrow([] as [MyLabel; 0]).unwrap(),
2490+
<MyLabel as re_types_core::Loggable>::to_arrow([] as [MyLabel; 0]).unwrap(),
24842491
), //
24852492
]
24862493
.into_iter()
@@ -2495,15 +2502,17 @@ mod tests {
24952502
components: [
24962503
(
24972504
MyPoint::name(),
2498-
MyPoint::to_arrow([] as [MyPoint; 0]).unwrap(),
2505+
<MyPoint as re_types_core::Loggable>::to_arrow([] as [MyPoint; 0]).unwrap(),
24992506
), //
25002507
(
25012508
MyColor::name(),
2502-
MyColor::to_arrow([MyColor(0xFFFF_FFFF)]).unwrap(),
2509+
<MyColor as re_types_core::Loggable>::to_arrow([MyColor(0xFFFF_FFFF)])
2510+
.unwrap(),
25032511
), //
25042512
(
25052513
MyLabel::name(),
2506-
MyLabel::to_arrow([MyLabel("hey".into())]).unwrap(),
2514+
<MyLabel as re_types_core::Loggable>::to_arrow([MyLabel("hey".into())])
2515+
.unwrap(),
25072516
), //
25082517
]
25092518
.into_iter()

0 commit comments

Comments
 (0)