move the locally scoped function to an impl to improve readability

This commit is contained in:
Noa Aarts 2024-12-10 22:40:53 +01:00
parent 8969a9e6d5
commit c5fb0f5437
Signed by: noa
GPG key ID: 1850932741EFF672

View file

@ -28,15 +28,7 @@ impl Multipart {
}
}
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>> {
impl Multipart {
fn write_multipart_frame<T>(
obj: T,
boundary: Vec<u8>,
@ -70,7 +62,17 @@ where
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 headers = self.headers.clone();
let first = self.first;
@ -79,8 +81,12 @@ where
stream.map(move |obj_res| match obj_res {
Err(e) => Err(e),
Ok(obj) => {
let picture_framed =
write_multipart_frame(obj, boundary.clone(), headers.clone(), first);
let picture_framed = Multipart::write_multipart_frame(
obj,
boundary.clone(),
headers.clone(),
first,
);
picture_framed.map(axum::body::Bytes::from)
}