Skip to main content

BlobStream

Struct BlobStream 

Source
pub struct BlobStream<'a, S: ConnectionState = Ready> { /* private fields */ }
Expand description

A stream of rows whose trailing MAX column is read incrementally from the socket. See the module docs. Obtain one from Client::query_stream_blob.

Implementations§

Source§

impl<'a, S: ConnectionState> BlobStream<'a, S>

Source

pub fn columns(&self) -> &[Column]

The leading (scalar) columns of the result set — everything before the trailing MAX column(s).

Source

pub fn blob_columns(&self) -> &[Column]

The trailing MAX (blob) columns of the result set, in wire order.

For a query_stream_blob stream this is a single column; for query_stream_rows it is the run of trailing MAX columns, in the order next_blob visits them.

Source

pub fn current_blob_column(&self) -> Option<&Column>

The column metadata of the currently positioned blob, or None before the first blob of a row is positioned (or after the row is exhausted).

Source

pub async fn next(&mut self) -> Result<Option<Row>>

Advance to the next row, returning its scalar columns.

Auto-drains any unread trailing blob(s) of the previous row, so the wire stays aligned. Returns Ok(None) at end of stream (connection clean).

Source

pub async fn next_blob(&mut self) -> Result<bool>

Advance to the next trailing MAX column of the current row, returning true while one is positioned and false once the row’s blobs are exhausted.

Auto-drains the previously positioned blob (if not fully read) before advancing, so the wire stays aligned. After this returns true, read the blob with read_chunk / copy_blob_to and inspect it with current_blob_column / blob_is_null / blob_len.

This is the iteration primitive for query_stream_rows:

let mut stream = client
    .query_stream_rows("SELECT id, doc1, doc2 FROM files", &[])
    .await?;
while let Some(row) = stream.next().await? {
    let id: i32 = row.get_by_name("id")?;
    let _ = id;
    while stream.next_blob().await? {
        stream.copy_blob_to(&mut sink).await?; // each trailing MAX column
    }
}
Source

pub async fn read_chunk(&mut self) -> Result<Option<Bytes>>

Read the next chunk of the current blob, or None when it is fully read (or NULL). Reads more packets from the socket as needed.

Chunks are raw bytes, not decoded text. For an NVARCHAR(MAX) / XML column the bytes are little-endian UCS-2, and a chunk boundary can fall in the middle of a two-byte code unit (or a surrogate pair) — so do not decode each chunk to str independently. Concatenate the chunks first (or stream to a byte sink), then decode the whole value.

Source

pub async fn copy_blob_to<W>(&mut self, w: &mut W) -> Result<u64>
where W: AsyncWrite + Unpin,

Stream the current row’s blob to an async writer, returning bytes written.

Source

pub fn blob_len(&self) -> Option<u64>

The current row’s blob length in bytes, once known (after the first chunk is read). None before that, for a NULL blob, or for an unknown-length value.

Source

pub fn blob_is_null(&self) -> bool

Whether the current row’s blob is NULL.

Auto Trait Implementations§

§

impl<'a, S = Ready> !Freeze for BlobStream<'a, S>

§

impl<'a, S = Ready> !RefUnwindSafe for BlobStream<'a, S>

§

impl<'a, S = Ready> !UnwindSafe for BlobStream<'a, S>

§

impl<'a, S> Send for BlobStream<'a, S>
where S: Send,

§

impl<'a, S> Sync for BlobStream<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for BlobStream<'a, S>

§

impl<'a, S> UnsafeUnpin for BlobStream<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more