Skip to content

Commit

Permalink
Revert "Remove Datatype and DatatypeBatch (#7256)"
Browse files Browse the repository at this point in the history
This reverts commit 2e2a988.
  • Loading branch information
emilk committed Aug 28, 2024
1 parent ce890c5 commit 0c06ff7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/store/re_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub mod components {

/// The low-level datatypes that [`components`] are built from.
///
/// They all implement the [`Loggable`] trait.
/// They all implement the [`Datatype`] trait.
pub mod datatypes {

// Some datatypes are so fundamental and used everywhere that we want them to be exposed
Expand Down
8 changes: 4 additions & 4 deletions crates/store/re_types_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! When multiple instances of a [`Component`] are put together in an array, they yield a
//! [`ComponentBatch`]: the atomic unit of (de)serialization.
//!
//! Internally, [`Component`]s are implemented using many different [`Loggable`]s.
//! Internally, [`Component`]s are implemented using many different [`Datatype`]s.
//!
//! ## Feature flags
#![doc = document_features::document_features!()]
Expand Down Expand Up @@ -95,8 +95,8 @@ pub use self::{
},
arrow_buffer::ArrowBuffer,
arrow_string::ArrowString,
loggable::{Component, ComponentName, ComponentNameSet, DatatypeName, Loggable},
loggable_batch::{ComponentBatch, LoggableBatch, MaybeOwnedComponentBatch},
loggable::{Component, ComponentName, ComponentNameSet, Datatype, DatatypeName, Loggable},
loggable_batch::{ComponentBatch, DatatypeBatch, LoggableBatch, MaybeOwnedComponentBatch},
result::{
DeserializationError, DeserializationResult, ResultExt, SerializationError,
SerializationResult, _Backtrace,
Expand All @@ -117,7 +117,7 @@ pub mod archetypes;
/// There are also re-exported by `re_types`.
pub mod components;

/// Fundamental datatypes that are implemented in `re_types_core` directly for convenience and
/// Fundamental [`Datatype`]s that are implemented in `re_types_core` directly for convenience and
/// dependency optimization.
///
/// There are also re-exported by `re_types`.
Expand Down
21 changes: 15 additions & 6 deletions crates/store/re_types_core/src/loggable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
};

#[allow(unused_imports)] // used in docstrings
use crate::{Archetype, ComponentBatch, LoggableBatch};
use crate::{Archetype, ComponentBatch, DatatypeBatch, LoggableBatch};

// ---

Expand All @@ -14,12 +14,13 @@ use crate::{Archetype, ComponentBatch, LoggableBatch};
/// Internally, Arrow, and by extension Rerun, only deal with arrays of data.
/// We refer to individual entries in these arrays as instances.
///
/// [`Component`] is a specialization of the [`Loggable`] trait where [`Loggable::Name`] ==
/// [`ComponentName`].
/// [`Datatype`] and [`Component`] are specialization of the [`Loggable`] trait that are
/// automatically implemented based on the type used for [`Loggable::Name`].
///
/// Implementing the [`Loggable`] trait (and by extension [`Component`]) automatically derives the
/// [`LoggableBatch`] implementation (and by extension [`ComponentBatch`]), which makes it possible to
/// work with lists' worth of data in a generic fashion.
/// Implementing the [`Loggable`] trait (and by extension [`Datatype`]/[`Component`])
/// automatically derives the [`LoggableBatch`] implementation (and by extension
/// [`DatatypeBatch`]/[`ComponentBatch`]), which makes it possible to work with lists' worth of data
/// in a generic fashion.
pub trait Loggable: 'static + Send + Sync + Clone + Sized + SizeBytes {
type Name: std::fmt::Display;

Expand Down Expand Up @@ -126,6 +127,14 @@ pub trait Loggable: 'static + Send + Sync + Clone + Sized + SizeBytes {
}
}

/// A [`Datatype`] describes plain old data that can be used by any number of [`Component`]s.
///
/// Any [`Loggable`] with a [`Loggable::Name`] set to [`DatatypeName`] automatically implements
/// [`Datatype`].
pub trait Datatype: Loggable<Name = DatatypeName> {}

impl<L: Loggable<Name = DatatypeName>> Datatype for L {}

/// A [`Component`] describes semantic data that can be used by any number of [`Archetype`]s.
///
/// Any [`Loggable`] with a [`Loggable::Name`] set to [`ComponentName`] automatically implements
Expand Down
28 changes: 27 additions & 1 deletion crates/store/re_types_core/src/loggable_batch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Component, ComponentName, Loggable, SerializationResult};
use crate::{Component, ComponentName, Datatype, DatatypeName, Loggable, SerializationResult};

#[allow(unused_imports)] // used in docstrings
use crate::Archetype;
Expand Down Expand Up @@ -34,6 +34,12 @@ pub trait LoggableBatch {
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>>;
}

/// A [`DatatypeBatch`] represents an array's worth of [`Datatype`] instances.
///
/// Any [`LoggableBatch`] with a [`Loggable::Name`] set to [`DatatypeName`] automatically
/// implements [`DatatypeBatch`].
pub trait DatatypeBatch: LoggableBatch<Name = DatatypeName> {}

/// A [`ComponentBatch`] represents an array's worth of [`Component`] instances.
///
/// Any [`LoggableBatch`] with a [`Loggable::Name`] set to [`ComponentName`] automatically
Expand Down Expand Up @@ -137,6 +143,8 @@ impl<L: Clone + Loggable> LoggableBatch for L {
}
}

impl<D: Datatype> DatatypeBatch for D {}

impl<C: Component> ComponentBatch for C {}

// --- Unary Option ---
Expand Down Expand Up @@ -165,6 +173,8 @@ impl<L: Clone + Loggable> LoggableBatch for Option<L> {
}
}

impl<D: Datatype> DatatypeBatch for Option<D> {}

impl<C: Component> ComponentBatch for Option<C> {}

// --- Vec ---
Expand Down Expand Up @@ -193,6 +203,8 @@ impl<L: Clone + Loggable> LoggableBatch for Vec<L> {
}
}

impl<D: Datatype> DatatypeBatch for Vec<D> {}

impl<C: Component> ComponentBatch for Vec<C> {}

// --- Vec<Option> ---
Expand Down Expand Up @@ -224,6 +236,8 @@ impl<L: Loggable> LoggableBatch for Vec<Option<L>> {
}
}

impl<D: Datatype> DatatypeBatch for Vec<Option<D>> {}

impl<C: Component> ComponentBatch for Vec<Option<C>> {}

// --- Array ---
Expand Down Expand Up @@ -252,6 +266,8 @@ impl<L: Loggable, const N: usize> LoggableBatch for [L; N] {
}
}

impl<D: Datatype, const N: usize> DatatypeBatch for [D; N] {}

impl<C: Component, const N: usize> ComponentBatch for [C; N] {}

// --- Array<Option> ---
Expand Down Expand Up @@ -283,6 +299,8 @@ impl<L: Loggable, const N: usize> LoggableBatch for [Option<L>; N] {
}
}

impl<D: Datatype, const N: usize> DatatypeBatch for [Option<D>; N] {}

impl<C: Component, const N: usize> ComponentBatch for [Option<C>; N] {}

// --- Slice ---
Expand Down Expand Up @@ -311,6 +329,8 @@ impl<'a, L: Loggable> LoggableBatch for &'a [L] {
}
}

impl<'a, D: Datatype> DatatypeBatch for &'a [D] {}

impl<'a, C: Component> ComponentBatch for &'a [C] {}

// --- Slice<Option> ---
Expand Down Expand Up @@ -342,6 +362,8 @@ impl<'a, L: Loggable> LoggableBatch for &'a [Option<L>] {
}
}

impl<'a, D: Datatype> DatatypeBatch for &'a [Option<D>] {}

impl<'a, C: Component> ComponentBatch for &'a [Option<C>] {}

// --- ArrayRef ---
Expand Down Expand Up @@ -370,6 +392,8 @@ impl<'a, L: Loggable, const N: usize> LoggableBatch for &'a [L; N] {
}
}

impl<'a, D: Datatype, const N: usize> DatatypeBatch for &'a [D; N] {}

impl<'a, C: Component, const N: usize> ComponentBatch for &'a [C; N] {}

// --- ArrayRef<Option> ---
Expand Down Expand Up @@ -401,4 +425,6 @@ impl<'a, L: Loggable, const N: usize> LoggableBatch for &'a [Option<L>; N] {
}
}

impl<'a, D: Datatype, const N: usize> DatatypeBatch for &'a [Option<D>; N] {}

impl<'a, C: Component, const N: usize> ComponentBatch for &'a [Option<C>; N] {}
6 changes: 3 additions & 3 deletions crates/top/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ pub mod time {
pub use time::{Time, TimePoint, Timeline};

pub use re_types_core::{
Archetype, ArchetypeName, AsComponents, Component, ComponentBatch, ComponentName, DatatypeName,
GenericIndicatorComponent, Loggable, LoggableBatch, MaybeOwnedComponentBatch,
NamedIndicatorComponent, SizeBytes,
Archetype, ArchetypeName, AsComponents, Component, ComponentBatch, ComponentName, Datatype,
DatatypeBatch, DatatypeName, GenericIndicatorComponent, Loggable, LoggableBatch,
MaybeOwnedComponentBatch, NamedIndicatorComponent, SizeBytes,
};

#[cfg(feature = "data_loaders")]
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/all/tutorials/custom_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl rerun::AsComponents for CustomPoints3D {

// ---

/// A custom [`rerun::Component`] that is backed by a builtin [`rerun::Float32`] scalar.
/// A custom [`rerun::Component`] that is backed by a builtin [`rerun::Float32`] scalar [`rerun::Datatype`].
#[derive(Debug, Clone, Copy)]
struct Confidence(rerun::Float32);

Expand Down

0 comments on commit 0c06ff7

Please sign in to comment.