pub struct RowPacker<'a> {
row: &'a mut Row,
}Expand description
Packs datums into a Row.
Creating a RowPacker via Row::packer starts a packing operation on the
row. A packing operation always starts from scratch: the existing contents
of the underlying row are cleared.
To complete a packing operation, drop the RowPacker.
Fields§
§row: &'a mut RowImplementations§
Source§impl RowPacker<'_>
impl RowPacker<'_>
pub(crate) fn try_push_proto(&mut self, x: &ProtoDatum) -> Result<(), String>
Source§impl RowPacker<'_>
impl RowPacker<'_>
Sourcepub fn for_existing_row(row: &mut Row) -> RowPacker<'_>
pub fn for_existing_row(row: &mut Row) -> RowPacker<'_>
Constructs a row packer that will pack additional datums into the provided row.
This function is intentionally somewhat inconvenient to call. You
usually want to call Row::packer instead to start packing from
scratch.
Sourcepub fn try_extend<'a, I, E, D>(&mut self, iter: I) -> Result<(), E>
pub fn try_extend<'a, I, E, D>(&mut self, iter: I) -> Result<(), E>
Extend an existing Row with additional Datums.
In the case the iterator produces an error, the pushing of
datums in terminated and the error returned. The Row will
be incomplete, but it will be safe to read datums from it.
Sourcepub fn extend_by_row(&mut self, row: &Row)
pub fn extend_by_row(&mut self, row: &Row)
Appends the datums of an entire Row.
Sourcepub unsafe fn extend_by_slice_unchecked(&mut self, data: &[u8])
pub unsafe fn extend_by_slice_unchecked(&mut self, data: &[u8])
Appends the slice of data representing an entire Row. The data is not validated.
§Safety
The requirements from Row::from_bytes_unchecked apply here, too:
This method relies on data being an appropriate row encoding, and can
result in unsafety if this is not the case.
Sourcepub fn push_list_with<F, R>(&mut self, f: F) -> R
pub fn push_list_with<F, R>(&mut self, f: F) -> R
Pushes a DatumList that is built from a closure.
The supplied closure will be invoked once with a Row that can be used
to populate the list. It is valid to call any method on the
RowPacker except for RowPacker::clear, RowPacker::truncate,
or RowPacker::truncate_datums.
Returns the value returned by the closure, if any.
let mut row = Row::default();
row.packer().push_list_with(|row| {
row.push(Datum::String("age"));
row.push(Datum::Int64(42));
});
assert_eq!(
row.unpack_first().unwrap_list().iter().collect::<Vec<_>>(),
vec![Datum::String("age"), Datum::Int64(42)],
);Sourcepub fn push_dict_with<F, R>(&mut self, f: F) -> R
pub fn push_dict_with<F, R>(&mut self, f: F) -> R
Pushes a DatumMap that is built from a closure.
The supplied closure will be invoked once with a Row that can be used
to populate the dict.
The closure must alternate pushing string keys and arbitrary values, otherwise reading the dict will cause a panic.
The closure must push keys in ascending order, otherwise equality
checks on the resulting Row may be wrong and reading the dict IN DEBUG
MODE will cause a panic.
The closure must not call RowPacker::clear,
RowPacker::truncate, or RowPacker::truncate_datums.
§Example
let mut row = Row::default();
row.packer().push_dict_with(|row| {
// key
row.push(Datum::String("age"));
// value
row.push(Datum::Int64(42));
// key
row.push(Datum::String("name"));
// value
row.push(Datum::String("bob"));
});
assert_eq!(
row.unpack_first().unwrap_map().iter().collect::<Vec<_>>(),
vec![("age", Datum::Int64(42)), ("name", Datum::String("bob"))]
);Sourcepub fn try_push_array<'a, I, D>(
&mut self,
dims: &[ArrayDimension],
iter: I,
) -> Result<(), InvalidArrayError>
pub fn try_push_array<'a, I, D>( &mut self, dims: &[ArrayDimension], iter: I, ) -> Result<(), InvalidArrayError>
Convenience function to construct an array from an iter of Datums.
Returns an error if the number of elements in iter does not match
the cardinality of the array as described by dims, or if the
number of dimensions exceeds MAX_ARRAY_DIMENSIONS. If an error
occurs, the packer’s state will be unchanged.
Sourcepub unsafe fn push_array_with_unchecked<F, E>(
&mut self,
dims: &[ArrayDimension],
f: F,
) -> Result<(), E>
pub unsafe fn push_array_with_unchecked<F, E>( &mut self, dims: &[ArrayDimension], f: F, ) -> Result<(), E>
Convenience function to construct an array from a function. The function must return the number of elements it pushed into the array. It is undefined behavior if the function returns a number different to the number of elements it pushed.
Returns an error if the number of elements pushed by f does not match
the cardinality of the array as described by dims, or if the
number of dimensions exceeds MAX_ARRAY_DIMENSIONS, or if f errors. If an error
occurs, the packer’s state will be unchanged.
Sourcepub fn push_array_with_row_major<F, I>(
&mut self,
dims: I,
f: F,
) -> Result<(), InvalidArrayError>
pub fn push_array_with_row_major<F, I>( &mut self, dims: I, f: F, ) -> Result<(), InvalidArrayError>
Pushes an Array that is built from a closure.
WARNING: This is fairly “sharp” tool that is easy to get wrong. You
should prefer RowPacker::try_push_array when possible.
Returns an error if the number of elements pushed does not match
the cardinality of the array as described by dims, or if the
number of dimensions exceeds MAX_ARRAY_DIMENSIONS. If an error
occurs, the packer’s state will be unchanged.
Sourcepub fn push_list<'a, I, D>(&mut self, iter: I)
pub fn push_list<'a, I, D>(&mut self, iter: I)
Convenience function to push a DatumList from an iter of Datums
See RowPacker::push_dict_with if you need to be able to handle errors
Sourcepub fn push_dict<'a, I, D>(&mut self, iter: I)
pub fn push_dict<'a, I, D>(&mut self, iter: I)
Convenience function to push a DatumMap from an iter of (&str, Datum) pairs
Sourcepub fn push_range<'a>(
&mut self,
range: Range<Datum<'a>>,
) -> Result<(), InvalidRangeError>
pub fn push_range<'a>( &mut self, range: Range<Datum<'a>>, ) -> Result<(), InvalidRangeError>
Pushes a Datum::Range derived from the Range<Datum<'a>.
§Panics
- If lower and upper express finite values and they are datums of different types.
- If lower or upper express finite values and are equal to
Datum::Null. To handleDatum::Nullproperly, useRangeBound::new.
§Notes
- This function canonicalizes the range before pushing it to the row.
- Prefer this function over
push_range_withbecause of its canonicaliztion. - Prefer creating
RangeBounds usingRangeBound::new, which handlesDatum::Nullin a SQL-friendly way.
Sourcepub fn push_range_with<L, U, E>(
&mut self,
lower: RangeLowerBound<L>,
upper: RangeUpperBound<U>,
) -> Result<(), E>
pub fn push_range_with<L, U, E>( &mut self, lower: RangeLowerBound<L>, upper: RangeUpperBound<U>, ) -> Result<(), E>
Pushes a DatumRange built from the specified arguments.
§Warning
Unlike push_range, push_range_with does not canonicalize its
inputs. Consequentially, this means it’s possible to generate ranges
that will not reflect the proper ordering and equality.
§Panics
- If lower or upper expresses a finite value and does not push exactly
one value into the
RowPacker. - If lower and upper express finite values and they are datums of different types.
- If lower or upper express finite values and push
Datum::Null.
§Notes
- Prefer
push_range_withover this function. This function should be used only when you are not pushingDatums to the inner row. - Range encoding is
[<flag bytes>,<lower>?,<upper>?], wherelowerandupperare optional, contingent on the flag value expressing an empty range (where neither will be present) or infinite bounds (where each infinite bound will be absent). - To push an emtpy range, use
push_rangeusingRange { inner: None }.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the contents of the packer without de-allocating its backing memory.
Sourcepub unsafe fn truncate(&mut self, pos: usize)
pub unsafe fn truncate(&mut self, pos: usize)
Truncates the underlying storage to the specified byte position.
§Safety
pos MUST specify a byte offset that lies on a datum boundary.
If pos specifies a byte offset that is within a datum, the row
packer will produce an invalid row, the unpacking of which may
trigger undefined behavior!
To find the byte offset of a datum boundary, inspect the packer’s
byte length by calling packer.data().len() after pushing the desired
number of datums onto the packer.
Sourcepub fn truncate_datums(&mut self, n: usize)
pub fn truncate_datums(&mut self, n: usize)
Truncates the underlying row to contain at most the first n datums.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RowPacker<'a>
impl<'a> RefUnwindSafe for RowPacker<'a>
impl<'a> Send for RowPacker<'a>
impl<'a> Sync for RowPacker<'a>
impl<'a> Unpin for RowPacker<'a>
impl<'a> !UnwindSafe for RowPacker<'a>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
Source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto.Source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto.Source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
Source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign, for types that do not implement AddAssign.