Skip to main content

ReqwestStreamOptions

Struct ReqwestStreamOptions 

Source
#[non_exhaustive]
pub struct ReqwestStreamOptions { pub max_obj_len: usize, pub buf_capacity: usize, pub on_error: Option<ReqwestStreamErrorHandler>, pub on_progress: Option<ReqwestStreamProgressHandler>, pub progress_interval: Option<Duration>, pub progress_items: Option<u64>, }
Expand description

Options shared by every streaming format.

Build these with ReqwestStreamOptions::new and the setters below rather than with a struct literal, so that later options can be added without breaking you.

§Note on max_obj_len

Unlike the positional-argument methods, which make you choose a limit, a freshly built ReqwestStreamOptions does not limit object size — max_obj_len defaults to usize::MAX. Set it explicitly when reading from a source you do not control.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§max_obj_len: usize§buf_capacity: usize§on_error: Option<ReqwestStreamErrorHandler>§on_progress: Option<ReqwestStreamProgressHandler>§progress_interval: Option<Duration>§progress_items: Option<u64>

Implementations§

Source§

impl ReqwestStreamOptions

Source

pub fn new() -> Self

Source

pub fn max_obj_len(self, max_obj_len: usize) -> Self

The maximum size in bytes of a single decoded object.

usize::MAX, the default, means no limit.

Source

pub fn buf_capacity(self, buf_capacity: usize) -> Self

The initial capacity of the stream’s decoding buffer.

Source

pub fn on_error<F>(self, handler: F) -> Self
where F: Fn(&StreamBodyError) + Send + Sync + 'static,

Registers a callback invoked for every error produced while reading the response, covering both transport errors and decoding errors produced by the format itself.

The error is still yielded by the stream; this is purely an observation hook. It does not replace the tracing feature: when that feature is enabled both the log event and this callback fire.

Source

pub fn on_progress<F>(self, handler: F) -> Self
where F: Fn(&ReqwestStreamProgress) + Send + Sync + 'static,

Registers a callback receiving progress snapshots while the response is read: one per reporting interval or item step, plus a final one carrying the totals and how the stream ended (completed, failed, or aborted because the consumer stopped reading).

This is the same accounting the tracing feature reports, exposed for metrics: wire it to a counter and you get streamed items and bytes without depending on tracing at all. When the feature is enabled both happen.

The counters are only maintained when someone is listening, so a stream with no callback and no tracing subscriber interested in reqwest_streams pays nothing.

Source

pub fn progress_interval(self, interval: Duration) -> Self

Reports progress at most once per interval (one second by default).

Set the field to None directly to report on item steps only.

Source

pub fn progress_items(self, items: u64) -> Self

Additionally reports progress every items items.

Off by default, and deliberately so: it is a linear step, so a large stream reports a number of times proportional to its size. Prefer Self::progress_interval unless you specifically want item-granular checkpoints.

Trait Implementations§

Source§

impl Default for ReqwestStreamOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<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