move the locally scoped function to an impl to improve readability
This commit is contained in:
parent
8969a9e6d5
commit
c5fb0f5437
1 changed files with 42 additions and 36 deletions
|
|
@ -28,15 +28,7 @@ impl Multipart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> StreamingFormat<T> for Multipart
|
impl Multipart {
|
||||||
where
|
|
||||||
T: Send + Sync + IntoIterator<Item = u8> + 'static,
|
|
||||||
{
|
|
||||||
fn to_bytes_stream<'a, 'b>(
|
|
||||||
&'a self,
|
|
||||||
stream: futures::stream::BoxStream<'b, Result<T, axum::Error>>,
|
|
||||||
_options: &'a axum_streams::StreamBodyAsOptions,
|
|
||||||
) -> futures::stream::BoxStream<'b, Result<axum::body::Bytes, axum::Error>> {
|
|
||||||
fn write_multipart_frame<T>(
|
fn write_multipart_frame<T>(
|
||||||
obj: T,
|
obj: T,
|
||||||
boundary: Vec<u8>,
|
boundary: Vec<u8>,
|
||||||
|
|
@ -70,7 +62,17 @@ where
|
||||||
|
|
||||||
Ok(frame_vec)
|
Ok(frame_vec)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StreamingFormat<T> for Multipart
|
||||||
|
where
|
||||||
|
T: Send + Sync + IntoIterator<Item = u8> + 'static,
|
||||||
|
{
|
||||||
|
fn to_bytes_stream<'a, 'b>(
|
||||||
|
&'a self,
|
||||||
|
stream: futures::stream::BoxStream<'b, Result<T, axum::Error>>,
|
||||||
|
_options: &'a axum_streams::StreamBodyAsOptions,
|
||||||
|
) -> futures::stream::BoxStream<'b, Result<axum::body::Bytes, axum::Error>> {
|
||||||
let boundary = self.boundary.clone();
|
let boundary = self.boundary.clone();
|
||||||
let headers = self.headers.clone();
|
let headers = self.headers.clone();
|
||||||
let first = self.first;
|
let first = self.first;
|
||||||
|
|
@ -79,8 +81,12 @@ where
|
||||||
stream.map(move |obj_res| match obj_res {
|
stream.map(move |obj_res| match obj_res {
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
Ok(obj) => {
|
Ok(obj) => {
|
||||||
let picture_framed =
|
let picture_framed = Multipart::write_multipart_frame(
|
||||||
write_multipart_frame(obj, boundary.clone(), headers.clone(), first);
|
obj,
|
||||||
|
boundary.clone(),
|
||||||
|
headers.clone(),
|
||||||
|
first,
|
||||||
|
);
|
||||||
|
|
||||||
picture_framed.map(axum::body::Bytes::from)
|
picture_framed.map(axum::body::Bytes::from)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue