pub struct DataCell {
pub inner: Arc<DataCellInner>,
}
Expand description
A cell’s worth of data, i.e. a uniform array of values for a given component type. This is the leaf type in our data model.
A DataCell
can be constructed from either an iterable of native Component
s or directly
from a slice of arrow data.
Behind the scenes, a DataCell
is backed by an erased arrow array living on the heap, which
is likely to point into a larger batch of contiguous memory that it shares with its peers.
Cloning a DataCell
is thus cheap (shallow, ref-counted).
§Layout
A cell is an array of component instances: [C, C, C, …]
.
Consider this example:
let points: &[MyPoint] = &[[10.0, 10.0].into(), [20.0, 20.0].into(), [30.0, 30.0].into()];
let cell = DataCell::from(points);
// Or, alternatively:
let cell = DataCell::from_component::<MyPoint>([[10.0, 10.0], [20.0, 20.0], [30.0, 30.0]]);
The cell’s datatype is now a StructArray
:
Struct([
Field { name: "x", data_type: Float32, is_nullable: false, metadata: {} },
Field { name: "y", data_type: Float32, is_nullable: false, metadata: {} },
])
Or, visualized as a cell within a larger table:
┌──────────────────────────────────────────────────┐
│ rerun.components.Point2D │
╞══════════════════════════════════════════════════╡
│ [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}] │
└──────────────────────────────────────────────────┘
§Example
let points: &[MyPoint] = &[
MyPoint { x: 10.0, y: 10.0 },
MyPoint { x: 20.0, y: 20.0 },
MyPoint { x: 30.0, y: 30.0 },
];
let _cell = DataCell::from(points);
// Or, alternatively:
let cell = DataCell::from_component::<MyPoint>([
MyPoint { x: 10.0, y: 10.0 },
MyPoint { x: 20.0, y: 20.0 },
MyPoint { x: 30.0, y: 30.0 },
]);
eprintln!("{:#?}", cell.datatype());
eprintln!("{cell}");
Fields§
§inner: Arc<DataCellInner>
While the arrow data is already refcounted, the contents of the DataCell
still have to
be wrapped in an Arc
to work around performance issues in arrow2
.
See DataCellInner
for more information.
Implementations§
source§impl DataCell
impl DataCell
sourcepub fn from_component_batch(
batch: &dyn ComponentBatch<Name = ComponentName>
) -> Result<DataCell, SerializationError>
pub fn from_component_batch( batch: &dyn ComponentBatch<Name = ComponentName> ) -> Result<DataCell, SerializationError>
Builds a new DataCell
from a component batch.
sourcepub fn try_from_native<'a, C>(
values: impl IntoIterator<Item = impl Into<Cow<'a, C>>>
) -> Result<DataCell, DataCellError>
pub fn try_from_native<'a, C>( values: impl IntoIterator<Item = impl Into<Cow<'a, C>>> ) -> Result<DataCell, DataCellError>
Builds a new DataCell
from a uniform iterable of native component values.
Fails if the given iterable cannot be serialized to arrow, which should never happen when using Rerun’s built-in components.
sourcepub fn try_from_native_sparse<'a, C>(
values: impl IntoIterator<Item = Option<impl Into<Cow<'a, C>>>>
) -> Result<DataCell, DataCellError>
pub fn try_from_native_sparse<'a, C>( values: impl IntoIterator<Item = Option<impl Into<Cow<'a, C>>>> ) -> Result<DataCell, DataCellError>
Builds a new DataCell
from a uniform iterable of native component values.
Fails if the given iterable cannot be serialized to arrow, which should never happen when using Rerun’s built-in components.
sourcepub fn from_native<'a, C>(
values: impl IntoIterator<Item = impl Into<Cow<'a, C>>>
) -> DataCell
pub fn from_native<'a, C>( values: impl IntoIterator<Item = impl Into<Cow<'a, C>>> ) -> DataCell
Builds a new DataCell
from a uniform iterable of native component values.
Panics if the given iterable cannot be serialized to arrow, which should never happen when
using Rerun’s built-in components.
See Self::try_from_native
for the fallible alternative.
sourcepub fn from_native_sparse<'a, C>(
values: impl IntoIterator<Item = Option<impl Into<Cow<'a, C>>>>
) -> DataCell
pub fn from_native_sparse<'a, C>( values: impl IntoIterator<Item = Option<impl Into<Cow<'a, C>>>> ) -> DataCell
Builds a new DataCell
from a uniform iterable of native component values.
Panics if the given iterable cannot be serialized to arrow, which should never happen when
using Rerun’s built-in components.
See Self::try_from_native
for the fallible alternative.
sourcepub fn from_component<'a, C>(
values: impl IntoIterator<Item = impl Into<C>>
) -> DataCell
pub fn from_component<'a, C>( values: impl IntoIterator<Item = impl Into<C>> ) -> DataCell
Builds a cell from an iterable of items that can be turned into a Component
.
sourcepub fn from_component_sparse<'a, C>(
values: impl IntoIterator<Item = Option<impl Into<C>>>
) -> DataCell
pub fn from_component_sparse<'a, C>( values: impl IntoIterator<Item = Option<impl Into<C>>> ) -> DataCell
Builds a cell from an iterable of items that can be turned into a Component
.
sourcepub fn try_from_arrow(
name: ComponentName,
values: Box<dyn Array>
) -> Result<DataCell, DataCellError>
pub fn try_from_arrow( name: ComponentName, values: Box<dyn Array> ) -> Result<DataCell, DataCellError>
Builds a new DataCell
from an arrow array.
Fails if the array is not a valid list of components.
sourcepub fn from_arrow(name: ComponentName, values: Box<dyn Array>) -> DataCell
pub fn from_arrow(name: ComponentName, values: Box<dyn Array>) -> DataCell
Builds a new DataCell
from an arrow array.
Panics if the array is not a valid list of components.
See Self::try_from_arrow
for the fallible alternative.
sourcepub fn from_native_empty<C>() -> DataCellwhere
C: Component,
pub fn from_native_empty<C>() -> DataCellwhere
C: Component,
Builds an empty DataCell
from a native component type.
sourcepub fn try_from_arrow_empty(
name: ComponentName,
datatype: DataType
) -> Result<DataCell, DataCellError>
pub fn try_from_arrow_empty( name: ComponentName, datatype: DataType ) -> Result<DataCell, DataCellError>
Builds an empty DataCell
from an arrow datatype.
Fails if the datatype is not a valid component type.
sourcepub fn from_arrow_empty(name: ComponentName, datatype: DataType) -> DataCell
pub fn from_arrow_empty(name: ComponentName, datatype: DataType) -> DataCell
Builds an empty DataCell
from an arrow datatype.
Panics if the datatype is not a valid component type.
See Self::try_from_arrow_empty
for a fallible alternative.
sourcepub fn to_arrow(&self) -> Box<dyn Array>
pub fn to_arrow(&self) -> Box<dyn Array>
Returns the contents of the cell as an arrow array (shallow clone).
Avoid using raw arrow arrays unless you absolutely have to: prefer working directly with
DataCell
s, DataRow
s & DataTable
s instead.
If you do use them, try to keep the scope as short as possible: holding on to a raw array
might prevent the datastore from releasing memory from garbage collected data.
sourcepub fn as_arrow_ref(&self) -> &(dyn Array + 'static)
pub fn as_arrow_ref(&self) -> &(dyn Array + 'static)
Returns the contents of the cell as a reference to an arrow array.
Avoid using raw arrow arrays unless you absolutely have to: prefer working directly with
DataCell
s, DataRow
s & DataTable
s instead.
If you do use them, try to keep the scope as short as possible: holding on to a raw array
might prevent the datastore from releasing memory from garbage collected data.
sourcepub fn try_to_native<'a, C>(&'a self) -> Result<Vec<C>, DataCellError>where
C: Component + 'a,
pub fn try_to_native<'a, C>(&'a self) -> Result<Vec<C>, DataCellError>where
C: Component + 'a,
Returns the contents of the cell as an iterator of native components.
Fails if the underlying arrow data cannot be deserialized into C
.
sourcepub fn try_to_native_mono<'a, C>(&'a self) -> Result<Option<C>, DataCellError>where
C: Component + 'a,
pub fn try_to_native_mono<'a, C>(&'a self) -> Result<Option<C>, DataCellError>where
C: Component + 'a,
Returns the contents of an expected mono-component as an Option<C>
.
Fails if the underlying arrow data cannot be deserialized into C
.
sourcepub fn to_native<'a, C>(&'a self) -> Vec<C>where
C: Component + 'a,
pub fn to_native<'a, C>(&'a self) -> Vec<C>where
C: Component + 'a,
Returns the contents of the cell as an iterator of native components.
Panics if the underlying arrow data cannot be deserialized into C
.
See Self::try_to_native
for a fallible alternative.
sourcepub fn try_to_native_opt<'a, C>(
&'a self
) -> Result<Vec<Option<C>>, DataCellError>where
C: Component + 'a,
pub fn try_to_native_opt<'a, C>(
&'a self
) -> Result<Vec<Option<C>>, DataCellError>where
C: Component + 'a,
Returns the contents of the cell as an iterator of native optional components.
Fails if the underlying arrow data cannot be deserialized into C
.
sourcepub fn to_native_opt<'a, C>(&'a self) -> Vec<Option<C>>where
C: Component + 'a,
pub fn to_native_opt<'a, C>(&'a self) -> Vec<Option<C>>where
C: Component + 'a,
Returns the contents of the cell as an iterator of native optional components.
Panics if the underlying arrow data cannot be deserialized into C
.
See Self::try_to_native_opt
for a fallible alternative.
source§impl DataCell
impl DataCell
sourcepub fn component_name(&self) -> ComponentName
pub fn component_name(&self) -> ComponentName
The name of the component type stored in the cell.
sourcepub fn datatype(&self) -> &DataType
pub fn datatype(&self) -> &DataType
The type of the component stored in the cell, i.e. the cell is an array of that type.
sourcepub fn num_instances(&self) -> u32
pub fn num_instances(&self) -> u32
The length of the cell’s array, i.e. how many component instances are in the cell?
pub fn is_empty(&self) -> bool
sourcepub fn is_sorted_and_unique(&self) -> Result<bool, DataCellError>
pub fn is_sorted_and_unique(&self) -> Result<bool, DataCellError>
Returns true
if the underlying array is both sorted (increasing order) and contains only
unique values.
The cell must be dense, otherwise the result of this method is undefined.
source§impl DataCell
impl DataCell
sourcepub fn compute_size_bytes(&mut self) -> bool
pub fn compute_size_bytes(&mut self) -> bool
Compute and cache the total size (stack + heap) of the inner cell and its underlying arrow array, in bytes. This does nothing if the size has already been computed and cached before.
The caller must the sole owner of this cell, as this requires mutating an Arc
under the
hood. Returns false otherwise.
Beware: this is very costly!
Trait Implementations§
source§impl PartialEq for DataCell
impl PartialEq for DataCell
source§impl SizeBytes for DataCell
impl SizeBytes for DataCell
source§fn heap_size_bytes(&self) -> u64
fn heap_size_bytes(&self) -> u64
self
on the heap, in bytes.source§fn total_size_bytes(&self) -> u64
fn total_size_bytes(&self) -> u64
self
in bytes, accounting for both stack and heap space.source§fn stack_size_bytes(&self) -> u64
fn stack_size_bytes(&self) -> u64
self
on the stack, in bytes. Read moreAuto Trait Implementations§
impl Freeze for DataCell
impl !RefUnwindSafe for DataCell
impl Send for DataCell
impl Sync for DataCell
impl Unpin for DataCell
impl !UnwindSafe for DataCell
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more