Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow logging individual components directly (Impl AsComponents for all ObjectKind::Component) #7756

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/store/re_types_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ pub trait AsComponents {
}
}

impl<C: Component> AsComponents for C {
#[inline]
fn as_component_batches(&self) -> Vec<MaybeOwnedComponentBatch<'_>> {
vec![(self as &dyn ComponentBatch).into()]
}
}

// ---

mod archetype;
Expand Down
19 changes: 11 additions & 8 deletions crates/top/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ impl RecordingStream {
/// Log data to Rerun.
///
/// This is the main entry point for logging data to rerun. It can be used to log anything
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html).
/// that implements the [`AsComponents`], such as any [archetype](https://docs.rs/rerun/latest/rerun/archetypes/index.html)
/// or individual [component](https://docs.rs/rerun/latest/rerun/components/index.html).
///
/// The data will be timestamped automatically based on the [`RecordingStream`]'s internal clock.
/// See [`RecordingStream::set_time_sequence`] etc for more information.
Expand Down Expand Up @@ -889,9 +890,9 @@ impl RecordingStream {
pub fn log(
&self,
ent_path: impl Into<EntityPath>,
arch: &impl AsComponents,
as_components: &impl AsComponents,
) -> RecordingStreamResult<()> {
self.log_with_static(ent_path, false, arch)
self.log_with_static(ent_path, false, as_components)
}

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

#[deprecated(since = "0.16.0", note = "use `log_static` instead")]
Expand Down Expand Up @@ -1016,14 +1018,15 @@ impl RecordingStream {
&self,
ent_path: impl Into<EntityPath>,
static_: bool,
arch: &impl AsComponents,
as_components: &impl AsComponents,
) -> RecordingStreamResult<()> {
let row_id = RowId::new(); // Create row-id as early as possible. It has a timestamp and is used to estimate e2e latency.
self.log_component_batches_impl(
row_id,
ent_path,
static_,
arch.as_component_batches()
as_components
.as_component_batches()
.iter()
.map(|any_comp_batch| any_comp_batch.as_ref()),
)
Expand Down
Loading