pub trait ProtobufStreamResponse {
// Required method
fn protobuf_stream<'a, 'b, T>(
self,
max_obj_len: usize,
) -> impl Stream<Item = StreamBodyResult<T>> + Send + 'b
where T: Message + Default + Send + 'b;
}Available on crate feature
protobuf only.Expand description
Extension trait for reqwest::Response that provides streaming support for the Protobuf
format.
Required Methods§
Sourcefn protobuf_stream<'a, 'b, T>(
self,
max_obj_len: usize,
) -> impl Stream<Item = StreamBodyResult<T>> + Send + 'b
fn protobuf_stream<'a, 'b, T>( self, max_obj_len: usize, ) -> impl Stream<Item = StreamBodyResult<T>> + Send + 'b
Streams the response as batches of Protobuf messages.
The stream will deserialize prost::Messages as type T with a maximum size of
max_obj_len bytes.
§Example
use futures::{prelude::*, stream::BoxStream as _};
use reqwest_streams::ProtobufStreamResponse as _;
#[derive(Clone, prost::Message)]
struct MyTestStructure {
#[prost(string, tag = "1")]
some_test_field: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
const MAX_OBJ_LEN: usize = 64 * 1024;
let stream = reqwest::get("http://localhost:8080/protobuf")
.await?
.protobuf_stream::<MyTestStructure>(MAX_OBJ_LEN);
let _items: Vec<MyTestStructure> = stream.try_collect().await?;
Ok(())
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.