Struct repr::Row [−][src]
A packed representation for Datum
s.
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 Datum
s without any padding.
We avoid the need for the first set of padding by only providing access to the Datum
s 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 Datum
s 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)])
Row
s 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 Datum
s 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]
I: IntoIterator<Item = D>,
D: Borrow<Datum<'a>>,
Take some Datum
s 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]
I: IntoIterator<Item = Result<D, E>>,
D: Borrow<Datum<'a>>,
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 Datum
s 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]
impl Default for Row
[src]
impl<'de> Deserialize<'de> for Row
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Row
[src]
impl Eq for Row
[src]
impl Hash for Row
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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?
fn into_iter(self) -> DatumListIter<'a>
[src]
impl Ord for Row
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[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.
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Serialize for Row
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,