Struct ValueStream
pub struct ValueStream { /* private fields */ }Expand description
An async stream of Values with optional type checking.
ValueStream combines a buffered front-end with an optional async
[Stream] back-end. Values can be pushed into the buffer or pulled
from the underlying stream. When a Type is attached via
typed, every yielded value is checked at
runtime.
Implements [Stream] from tokio_stream, yielding
Result<Value> items.
§Examples
use toasty_core::stmt::{Value, ValueStream};
let mut stream = ValueStream::from_value(Value::from(42_i64));
let val = stream.next().await.unwrap().unwrap();
assert_eq!(val, Value::from(42_i64));Implementations§
§impl ValueStream
impl ValueStream
pub fn from_value(value: impl Into<Value>) -> ValueStream
pub fn from_value(value: impl Into<Value>) -> ValueStream
Creates a stream containing a single value.
pub fn from_stream<T>(stream: T) -> ValueStream
pub fn from_stream<T>(stream: T) -> ValueStream
Creates a stream backed by an async [Stream] of Result<Value>.
pub fn from_vec(records: Vec<Value>) -> ValueStream
pub fn from_vec(records: Vec<Value>) -> ValueStream
Creates a fully-buffered stream from a vector of values.
pub fn from_iter<T, I>(iter: I) -> ValueStream
pub fn from_iter<T, I>(iter: I) -> ValueStream
Creates a stream from a fallible iterator.
pub async fn tap(&mut self) -> Result<(), Error>
pub async fn tap(&mut self) -> Result<(), Error>
Force the stream to preload at least one record, if there are more records to stream.
pub fn min_len(&self) -> usize
pub fn min_len(&self) -> usize
Returns the minimum number of elements this stream will yield.
This is derived from the stream’s size_hint lower bound plus
the number of buffered elements.
pub async fn collect(self) -> Result<Vec<Value>, Error>
pub async fn collect(self) -> Result<Vec<Value>, Error>
Consumes the stream and collects all values into a Vec.
pub async fn dup(&mut self) -> Result<ValueStream, Error>
pub async fn dup(&mut self) -> Result<ValueStream, Error>
Fully buffers the stream and returns a clone of it.
After this call, both the original and the returned stream are fully buffered and contain the same values.
pub fn try_clone(&self) -> Option<ValueStream>
pub fn try_clone(&self) -> Option<ValueStream>
Returns a clone if the stream is fully buffered, or None if
there is an unconsumed async stream that cannot be cloned.
pub async fn buffer(&mut self) -> Result<(), Error>
pub async fn buffer(&mut self) -> Result<(), Error>
Drains the underlying async stream into the buffer.
After this call, all remaining values are buffered locally and
is_buffered returns true.
pub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns true if the ValueStream is fully buffered (no remaining stream)
pub fn buffered_to_vec(&self) -> Vec<Value>
pub fn buffered_to_vec(&self) -> Vec<Value>
Returns a clone of only the currently buffered values Does not consume any stream data or wait for additional values
pub fn typed(self, ty: Type) -> ValueStream
pub fn typed(self, ty: Type) -> ValueStream
Attaches a Type constraint to this stream.
Every value yielded from the stream (both already-buffered and
future) will be checked against ty at runtime. If a value does
not match, the check panics with a diagnostic message.
§Panics
Panics if an already-buffered value is not compatible with ty,
or if a previously set type differs from ty.
Trait Implementations§
§impl Debug for ValueStream
impl Debug for ValueStream
§impl Default for ValueStream
impl Default for ValueStream
§fn default() -> ValueStream
fn default() -> ValueStream
§impl From<Value> for ValueStream
impl From<Value> for ValueStream
§fn from(src: Value) -> ValueStream
fn from(src: Value) -> ValueStream
§impl From<Vec<Value>> for ValueStream
impl From<Vec<Value>> for ValueStream
§fn from(value: Vec<Value>) -> ValueStream
fn from(value: Vec<Value>) -> ValueStream
§impl Stream for ValueStream
impl Stream for ValueStream
§fn poll_next(
self: Pin<&mut ValueStream>,
cx: &mut Context<'_>,
) -> Poll<Option<<ValueStream as Stream>::Item>>
fn poll_next( self: Pin<&mut ValueStream>, cx: &mut Context<'_>, ) -> Poll<Option<<ValueStream as Stream>::Item>>
None if the stream is exhausted. Read moreAuto Trait Implementations§
impl Freeze for ValueStream
impl !RefUnwindSafe for ValueStream
impl Send for ValueStream
impl !Sync for ValueStream
impl Unpin for ValueStream
impl !UnwindSafe for ValueStream
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
§impl<St> StreamExt for Stwhere
St: Stream + ?Sized,
impl<St> StreamExt for Stwhere
St: Stream + ?Sized,
§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
None if the
stream is finished. Read more§fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
§fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
None. Read more§fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
§fn merge<U>(self, other: U) -> Merge<Self, U>where
U: Stream<Item = Self::Item>,
Self: Sized,
fn merge<U>(self, other: U) -> Merge<Self, U>where
U: Stream<Item = Self::Item>,
Self: Sized,
§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
None. Read more§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the underlying stream. Read more§fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
true. Read more§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n first items of the
underlying stream. Read more§fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
true. Read more