diff --git a/src/services/async_item_service.rs b/src/services/async_item_service.rs index 97798d5..cfd901c 100644 --- a/src/services/async_item_service.rs +++ b/src/services/async_item_service.rs @@ -240,22 +240,24 @@ impl AsyncItemService { let stream = tokio_stream::wrappers::ReceiverStream::new(rx); // If length is specified, we need to limit the stream - let limited_stream = if length > 0 { - // We need to track how many bytes we've sent - let mut bytes_sent = 0; - let limited = stream.take_while(move |result| { - if bytes_sent >= length { - return false; - } - if let Ok(chunk) = result { - bytes_sent += chunk.len() as u64; - } - true - }); - Box::pin(limited) - } else { - Box::pin(stream) - }; + // Use a trait object to ensure both branches have the same type + let limited_stream: std::pin::Pin> + Send>> = + if length > 0 { + // We need to track how many bytes we've sent + let mut bytes_sent = 0; + let limited = stream.take_while(move |result| { + if bytes_sent >= length { + return false; + } + if let Ok(chunk) = result { + bytes_sent += chunk.len() as u64; + } + true + }); + Box::pin(limited) + } else { + Box::pin(stream) + }; Ok((limited_stream, mime_type)) }