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§
Source§impl ValueStream
impl ValueStream
Sourcepub fn from_value(value: impl Into<Value>) -> ValueStream
pub fn from_value(value: impl Into<Value>) -> ValueStream
Creates a stream containing a single value.
Sourcepub 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>.
Sourcepub 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.
Sourcepub fn from_iter<T, I>(iter: I) -> ValueStream
pub fn from_iter<T, I>(iter: I) -> ValueStream
Creates a stream from a fallible iterator.
Sourcepub async fn next(&mut self) -> Option<Result<Value, Error>>
pub async fn next(&mut self) -> Option<Result<Value, Error>>
Returns the next record in the stream
Sourcepub async fn peek(&mut self) -> Option<Result<&Value, Error>>
pub async fn peek(&mut self) -> Option<Result<&Value, Error>>
Peek at the next record in the stream
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns true if the ValueStream is fully buffered (no remaining stream)
Sourcepub 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
Sourcepub 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§
Source§impl Debug for ValueStream
impl Debug for ValueStream
Source§impl Default for ValueStream
impl Default for ValueStream
Source§fn default() -> ValueStream
fn default() -> ValueStream
Source§impl From<Value> for ValueStream
impl From<Value> for ValueStream
Source§fn from(src: Value) -> ValueStream
fn from(src: Value) -> ValueStream
Source§impl Stream for ValueStream
impl Stream for ValueStream
Source§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 UnsafeUnpin 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
Source§impl<St> StreamExt for St
impl<St> StreamExt for St
Source§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 moreSource§fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
None. Read moreSource§fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
Source§fn merge<U>(self, other: U) -> Merge<Self, U>
fn merge<U>(self, other: U) -> Merge<Self, U>
Source§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
None. Read moreSource§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 moreSource§fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
true. Read moreSource§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 moreSource§fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
true. Read more