allow ResponseValue<ByteStream> to transfer ownership of interior Stream (#125)

This commit is contained in:
Joshua M. Clulow 2022-07-14 22:33:17 -07:00 committed by GitHub
parent 0c7cace799
commit 144ef6b9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 2 deletions

View File

@ -16,11 +16,20 @@ use serde::{de::DeserializeOwned, Serialize};
/// Represents an untyped byte stream for both success and error responses.
pub struct ByteStream(
Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send>>,
Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>>,
);
impl ByteStream {
pub fn into_inner(
self,
) -> Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>> {
self.0
}
}
impl Deref for ByteStream {
type Target = Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send>>;
type Target =
Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>>;
fn deref(&self) -> &Self::Target {
&self.0
@ -140,6 +149,15 @@ impl<T> ResponseValue<T> {
}
}
impl ResponseValue<ByteStream> {
/// Take ownership of the stream of bytes underpinning this response
pub fn into_inner_stream(
self,
) -> Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send + Sync>> {
self.into_inner().into_inner()
}
}
impl<T> Deref for ResponseValue<T> {
type Target = T;