Struct repr::Row[][src]

pub struct Row { /* fields omitted */ }

A packed representation for Datums.

Datum is easy to work with but very space inefficent. A Datum::Int32(42) is laid out in memory like this:

tag: 3 padding: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 data: 0 0 0 42 padding: 0 0 0 0 0 0 0 0 0 0 0 0

For a total of 32 bytes! The second set of padding is needed in case we were to write a Datum::Decimal into this location. The first set of padding is needed to align that hypothetical decimal to a 16 bytes boundary.

A Row stores zero or more Datums without any padding. We avoid the need for the first set of padding by only providing access to the Datums via calls to ptr::read_unaligned, which on modern x86 is barely penalized. We avoid the need for the second set of padding by not providing mutable access to the Datum. Instead, Row is append-only.

A Row can be built from a collection of Datums using Row::pack, but it often more efficient to use and re-use a RowPacker which can avoid unneccesary allocations. The Row::pack_slice method pre-determines the necessary allocation, and is also appropriate.

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
assert_eq!(row.unpack(), vec![Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)])

Rows can be unpacked by iterating over them:

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
assert_eq!(row.iter().nth(1).unwrap(), Datum::Int32(1));

If you want random access to the Datums in a Row, use Row::unpack to create a Vec<Datum>

let row = Row::pack_slice(&[Datum::Int32(0), Datum::Int32(1), Datum::Int32(2)]);
let datums = row.unpack();
assert_eq!(datums[1], Datum::Int32(1));

Performance

Rows are dynamically sized, but up to a fixed size their data is stored in-line. It is best to re-use a RowPacker across multiple Row creation calls, as this avoids the allocations involved in RowPacker::new().

Implementations

impl Row[src]

pub fn pack<'a, I, D>(iter: I) -> Row where
    I: IntoIterator<Item = D>,
    D: Borrow<Datum<'a>>, 
[src]

Take some Datums and pack them into a Row.

pub fn try_pack<'a, I, D, E>(iter: I) -> Result<Row, E> where
    I: IntoIterator<Item = Result<D, E>>,
    D: Borrow<Datum<'a>>, 
[src]

Like Row::pack, but the provided iterator is allowed to produce an error, in which case the packing operation is aborted and the error returned.

pub unsafe fn new(data: Vec<u8>) -> Self[src]

Creates a new row from supplied bytes.

Safety

This method relies on data being an appropriate row encoding, and can result in unsafety if this is not the case.

pub fn pack_slice<'a>(slice: &[Datum<'a>]) -> Row[src]

Pack a slice of Datums into a Row.

This method has the advantage over pack that it can determine the required allocation before packing the elements, ensuring only one allocation and no redundant copies required.

pub fn unpack(&self) -> Vec<Datum<'_>>[src]

Unpack self into a Vec<Datum> for efficient random access.

pub fn unpack_first(&self) -> Datum<'_>[src]

Return the first Datum in self

Panics if the Row is empty.

pub fn iter(&self) -> DatumListIter<'_>[src]

pub fn data(&self) -> &[u8][src]

For debugging only

Trait Implementations

impl Clone for Row[src]

impl Debug for Row[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Debug representation using the internal datums

impl Default for Row[src]

impl<'de> Deserialize<'de> for Row[src]

impl Display for Row[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Display representation using the internal datums

impl Eq for Row[src]

impl Hash for Row[src]

impl<'a> IntoIterator for &'a Row[src]

type Item = Datum<'a>

The type of the elements being iterated over.

type IntoIter = DatumListIter<'a>

Which kind of iterator are we turning this into?

impl Ord for Row[src]

impl PartialEq<Row> for Row[src]

impl PartialOrd<Row> for Row[src]

These implementations order first by length, and then by slice contents. This allows many comparisons to complete without dereferencing memory.

impl Serialize for Row[src]

impl StructuralEq for Row[src]

impl StructuralPartialEq for Row[src]

Auto Trait Implementations

impl RefUnwindSafe for Row[src]

impl Send for Row[src]

impl Sync for Row[src]

impl Unpin for Row[src]

impl UnwindSafe for Row[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.