pub struct DataRow {
pub row_id: RowId,
pub timepoint: TimePoint,
pub entity_path: EntityPath,
pub cells: DataCellRow,
}Expand description
A row’s worth of data, i.e. an event: a list of DataCells associated with an auto-generated
RowId, a user-specified TimePoint and EntityPath, and an expected number of
instances.
This is the middle layer in our data model.
Behind the scenes, a DataRow is backed by a collection of independent DataCells which
likely refer to unrelated/non-contiguous parts of the heap.
Cloning a DataRow is not too costly but needs to be avoided on the happy path.
§Field visibility
To facilitate destructuring (let DataRow { .. } = row), all the fields in DataRow are
public.
Modifying any of these fields from outside this crate is considered undefined behavior. Use the appropriate getters and setters instead.
§Layout
A row is a collection of cells where each cell can have an arbitrary number of
instances: [[C1, C1, C1], [], [C3], [C4, C4, C4], …].
Consider this example:
let points: &[MyPoint] = &[[10.0, 10.0].into(), [20.0, 20.0].into()];
let colors: &[_] = &[MyColor::from_rgb(128, 128, 128)];
let labels: &[MyLabel] = &[];
let row = DataRow::from_cells3(row_id, timepoint, ent_path, (points, colors, labels));A row has no arrow representation nor datatype of its own, as it is merely a collection of independent cells.
Visualized in the context of a larger table, it is simply a row of cells:
┌──────────────────────────────────┬─────────────────┬───────┐
│ Point2D ┆ Color ┆ Text │
╞══════════════════════════════════╪═════════════════╪═══════╡
│ [{x: 10, y: 10}, {x: 20, y: 20}] ┆ [2155905279] ┆ [] │
└──────────────────────────────────┴─────────────────┴───────┘
§Example
let points: &[MyPoint] = &[MyPoint { x: 10.0, y: 10.0}, MyPoint { x: 20.0, y: 20.0 }];
let colors: &[_] = &[MyColor(0xff7f7f7f)];
let labels: &[MyLabel] = &[];
let row = DataRow::from_cells3(
row_id,
"a/b/c",
timepoint,
(points, colors, labels),
).unwrap();
eprintln!("{row}");Fields§
§row_id: RowIdAuto-generated TUID, uniquely identifying this event and keeping track of the client’s
wall-clock.
timepoint: TimePointUser-specified TimePoint for this event.
entity_path: EntityPathUser-specified EntityPath for this event.
cells: DataCellRowThe actual cells (== columns, == components).
Implementations§
source§impl DataRow
impl DataRow
sourcepub fn from_archetype(
row_id: RowId,
timepoint: TimePoint,
entity_path: EntityPath,
as_components: &dyn AsComponents
) -> Result<DataRow, Error>
pub fn from_archetype( row_id: RowId, timepoint: TimePoint, entity_path: EntityPath, as_components: &dyn AsComponents ) -> Result<DataRow, Error>
Builds a new DataRow from anything implementing AsComponents.
sourcepub fn from_component_batches<'a>(
row_id: RowId,
timepoint: TimePoint,
entity_path: EntityPath,
comp_batches: impl IntoIterator<Item = &'a dyn ComponentBatch<Name = ComponentName>>
) -> Result<DataRow, Error>
pub fn from_component_batches<'a>( row_id: RowId, timepoint: TimePoint, entity_path: EntityPath, comp_batches: impl IntoIterator<Item = &'a dyn ComponentBatch<Name = ComponentName>> ) -> Result<DataRow, Error>
Builds a new DataRow from anything implementing AsComponents.
sourcepub fn from_cells(
row_id: RowId,
timepoint: impl Into<TimePoint>,
entity_path: impl Into<EntityPath>,
cells: impl IntoIterator<Item = DataCell>
) -> Result<DataRow, DataReadError>
pub fn from_cells( row_id: RowId, timepoint: impl Into<TimePoint>, entity_path: impl Into<EntityPath>, cells: impl IntoIterator<Item = DataCell> ) -> Result<DataRow, DataReadError>
Builds a new DataRow from an iterable of DataCells.
Fails if two or more cells share the same component type.
sourcepub fn into_table(self) -> DataTable
pub fn into_table(self) -> DataTable
Turns the DataRow into a single-row DataTable.
source§impl DataRow
impl DataRow
pub fn row_id(&self) -> RowId
pub fn timepoint(&self) -> &TimePoint
pub fn entity_path(&self) -> &EntityPath
pub fn num_cells(&self) -> usize
pub fn component_names(&self) -> impl ExactSizeIterator
pub fn cells(&self) -> &DataCellRow
pub fn into_cells(self) -> DataCellRow
sourcepub fn find_cell(&self, component: &ComponentName) -> Option<usize>
pub fn find_cell(&self, component: &ComponentName) -> Option<usize>
Returns the index of the cell with the given component type in the row, if it exists.
This is O(n).
sourcepub fn compute_all_size_bytes(&mut self)
pub fn compute_all_size_bytes(&mut self)
Compute and cache the total (heap) allocated size of each individual underlying
DataCell.
This does nothing for cells whose size has already been computed and cached before.
Beware: this is very costly!
source§impl DataRow
impl DataRow
sourcepub fn from_cells1_sized<C0>(
row_id: RowId,
entity_path: impl Into<EntityPath>,
timepoint: impl Into<TimePoint>,
into_cells: C0
) -> Result<DataRow, DataReadError>
pub fn from_cells1_sized<C0>( row_id: RowId, entity_path: impl Into<EntityPath>, timepoint: impl Into<TimePoint>, into_cells: C0 ) -> Result<DataRow, DataReadError>
A helper that combines Self::from_cells1 followed by Self::compute_all_size_bytes.
See respective documentations for more information.
Beware: this is costly!
pub fn from_cells1<C0>( row_id: RowId, entity_path: impl Into<EntityPath>, timepoint: impl Into<TimePoint>, into_cells: C0 ) -> Result<DataRow, DataRowError>
sourcepub fn from_cells2_sized<C0, C1>(
row_id: RowId,
entity_path: impl Into<EntityPath>,
timepoint: impl Into<TimePoint>,
into_cells: (C0, C1)
) -> Result<DataRow, DataRowError>
pub fn from_cells2_sized<C0, C1>( row_id: RowId, entity_path: impl Into<EntityPath>, timepoint: impl Into<TimePoint>, into_cells: (C0, C1) ) -> Result<DataRow, DataRowError>
A helper that combines Self::from_cells2 followed by Self::compute_all_size_bytes.
See respective documentations for more information.
Beware: this is costly!
pub fn from_cells2<C0, C1>( row_id: RowId, entity_path: impl Into<EntityPath>, timepoint: impl Into<TimePoint>, into_cells: (C0, C1) ) -> Result<DataRow, DataRowError>
pub fn from_cells3<C0, C1, C2>( row_id: RowId, entity_path: impl Into<EntityPath>, timepoint: impl Into<TimePoint>, into_cells: (C0, C1, C2) ) -> Result<DataRow, DataRowError>
Trait Implementations§
source§impl SizeBytes for DataRow
impl SizeBytes for DataRow
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 DataRow
impl !RefUnwindSafe for DataRow
impl Send for DataRow
impl Sync for DataRow
impl Unpin for DataRow
impl !UnwindSafe for DataRow
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