Skip to content

Commit 1155c22

Browse files
committed
revisit Rust API
1 parent 6bc21bf commit 1155c22

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

crates/store/re_types/src/any_values.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use nohash_hasher::IntMap;
55
use crate::{
66
ArchetypeFieldName, ArchetypeName, Component, ComponentDescriptor, SerializedComponentBatch,
77
};
8-
use re_types_core::{try_serialize_field, ComponentName};
8+
use re_types_core::{try_serialize_field, ComponentName, Loggable};
99

1010
const DEFAULT_ARCHETYPE_NAME: &str = "rerun.AnyValues";
1111
const DEFAULT_COMPONENT_NAME: &str = "rerun.component.AnyValue";
@@ -43,14 +43,14 @@ impl AnyValues {
4343
archetype_field_name: impl Into<ArchetypeFieldName>,
4444
array: arrow::array::ArrayRef,
4545
) -> Self {
46-
self.field_with_name(archetype_field_name, DEFAULT_COMPONENT_NAME, array)
46+
self.field_with_component_name(archetype_field_name, DEFAULT_COMPONENT_NAME, array)
4747
}
4848

4949
/// Adds a field of arbitrary data to this archetype.
5050
///
5151
/// In many cases, it might be more convenient to use [`Self::component`] to log an existing Rerun component instead.
5252
#[inline]
53-
pub fn field_with_name(
53+
pub fn field_with_component_name(
5454
mut self,
5555
archetype_field_name: impl Into<ArchetypeFieldName>,
5656
component_name: impl Into<ComponentName>,
@@ -78,18 +78,18 @@ impl AnyValues {
7878
archetype_field_name: impl Into<ArchetypeFieldName>,
7979
component: impl IntoIterator<Item = impl Into<C>>,
8080
) -> Self {
81-
self.component_with_name(archetype_field_name, C::name(), component)
81+
self.loggable(archetype_field_name, C::name(), component)
8282
}
8383

8484
/// Adds an existing Rerun [`Component`](crate::Component) to this archetype.
8585
///
8686
/// This method can be used to override the component name.
8787
#[inline]
88-
pub fn component_with_name<C: Component>(
88+
pub fn loggable<L: Loggable>(
8989
mut self,
9090
archetype_field_name: impl Into<ArchetypeFieldName>,
9191
component_name: impl Into<ComponentName>,
92-
component: impl IntoIterator<Item = impl Into<C>>,
92+
component: impl IntoIterator<Item = impl Into<L>>,
9393
) -> Self {
9494
let archetype_field_name = archetype_field_name.into();
9595
try_serialize_field(
@@ -117,16 +117,12 @@ mod test {
117117
fn simple() {
118118
let _ = AnyValues::default()
119119
.component::<components::Scalar>("confidence", [1.2f64, 3.4, 5.6])
120-
.component_with_name::<components::Text>(
121-
"homepage",
122-
"user.url",
123-
vec!["https://www.rerun.io"],
124-
)
120+
.loggable::<components::Text>("homepage", "user.url", vec!["https://www.rerun.io"])
125121
.field(
126122
"description",
127123
Arc::new(arrow::array::StringArray::from(vec!["Bla bla bla…"])),
128124
)
129-
.field_with_name(
125+
.field_with_component_name(
130126
"repository",
131127
"user.git",
132128
Arc::new(arrow::array::StringArray::from(vec![

crates/store/re_types_core/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ macro_rules! static_assert_struct_has_fields {
147147
/// merely be logged, not returned (except in debug builds, where all errors panic).
148148
#[doc(hidden)] // public so we can access it from re_types too
149149
#[allow(clippy::unnecessary_wraps)] // clippy gets confused in debug builds
150-
pub fn try_serialize_field<C: crate::Component>(
150+
pub fn try_serialize_field<L: Loggable>(
151151
descriptor: ComponentDescriptor,
152-
instances: impl IntoIterator<Item = impl Into<C>>,
152+
instances: impl IntoIterator<Item = impl Into<L>>,
153153
) -> Option<SerializedComponentBatch> {
154-
let res = C::to_arrow(
154+
let res = L::to_arrow(
155155
instances
156156
.into_iter()
157157
.map(|v| std::borrow::Cow::Owned(v.into())),

0 commit comments

Comments
 (0)