diff --git a/Cargo.toml b/Cargo.toml index 17e94a9..af3f178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,10 +21,11 @@ name = "axum_streams" path = "src/lib.rs" [dependencies] -axum = { version = "0.6" } +axum = { version = "0.7" } bytes = "1" futures-util = { version = "0.3", default-features = false, features = ["alloc"] } -http = "0.2" +http = "1" +http-body = "1" mime = "0.3" tokio = "1" serde = { version = "1", features = ["serde_derive"], optional = true } @@ -44,10 +45,10 @@ text = [] [dev-dependencies] futures = "0.3" -hyper = "0.14" +hyper = "1" reqwest = { version = "0.11", default-features = false, features = ["json", "stream", "multipart"] } tower = { version = "0.4", default-features = false, features = ["util", "make"] } -tower-http = { version = "0.4", features = ["util", "map-response-body"] } +tower-http = { version = "0.5", features = ["util", "map-response-body"] } tower-layer = "0.3" tower-service = "0.3" tokio = { version = "1", features = ["full"] } diff --git a/README.md b/README.md index fab6c4d..930aa91 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,14 @@ and want to avoid huge memory allocation. Cargo.toml: ```toml [dependencies] -axum-streams = { version = "0.10", features=["json", "csv", "protobuf", "text"] } +axum-streams = { version = "0.11", features=["json", "csv", "protobuf", "text"] } ``` ## Compatibility matrix | axum | axum-streams | |------|--------------| +| 0.7 | v0.11 | | 0.6 | v0.9-v0.10 | | 0.5 | 0.7 | diff --git a/src/stream_body_as.rs b/src/stream_body_as.rs index a8632e7..7d4295a 100644 --- a/src/stream_body_as.rs +++ b/src/stream_body_as.rs @@ -1,5 +1,4 @@ use crate::stream_format::StreamingFormat; -use axum::body::HttpBody; use axum::response::{IntoResponse, Response}; use futures::Stream; use futures_util::stream::BoxStream; @@ -7,9 +6,11 @@ use http::HeaderMap; use std::fmt::Formatter; use std::pin::Pin; use std::task::{Context, Poll}; +use axum::body::{Body, HttpBody}; +use http_body::Frame; pub struct StreamBodyAs<'a> { - stream: BoxStream<'a, Result>, + stream: BoxStream<'a, Result, axum::Error>>, trailers: Option, } @@ -46,7 +47,7 @@ impl IntoResponse for StreamBodyAs<'static> { HeaderMap::new() }; - let mut response = Response::new(axum::body::boxed(self)); + let mut response: Response = Response::new(Body::new(self)); *response.headers_mut() = headers; response } @@ -56,17 +57,11 @@ impl<'a> HttpBody for StreamBodyAs<'a> { type Data = axum::body::Bytes; type Error = axum::Error; - fn poll_data( + fn poll_frame( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - ) -> Poll>> { + ) -> Poll, Self::Error>>> { Pin::new(&mut self.stream).poll_next(cx) } - fn poll_trailers( - self: Pin<&mut Self>, - _cx: &mut Context<'_>, - ) -> Poll, Self::Error>> { - Poll::Ready(Ok(self.trailers.clone())) - } } diff --git a/src/stream_format.rs b/src/stream_format.rs index 4e1cbf0..f34d857 100644 --- a/src/stream_format.rs +++ b/src/stream_format.rs @@ -5,7 +5,7 @@ pub trait StreamingFormat { fn to_bytes_stream<'a, 'b>( &'a self, stream: BoxStream<'b, T>, - ) -> BoxStream<'b, Result>; + ) -> BoxStream<'b, Result, axum::Error>>; fn http_response_trailers(&self) -> Option; } diff --git a/src/text_format.rs b/src/text_format.rs index 72ac8af..ace4b2e 100644 --- a/src/text_format.rs +++ b/src/text_format.rs @@ -3,6 +3,7 @@ use futures::Stream; use futures_util::stream::BoxStream; use futures_util::StreamExt; use http::HeaderMap; +use http_body::Frame; pub struct TextStreamFormat; @@ -16,7 +17,7 @@ impl StreamingFormat for TextStreamFormat { fn to_bytes_stream<'a, 'b>( &'a self, stream: BoxStream<'b, String>, - ) -> BoxStream<'b, Result> { + ) -> BoxStream<'b, Result, axum::Error>> { fn write_text_record(obj: String) -> Result, axum::Error> { let obj_vec = obj.as_bytes().to_vec(); Ok(obj_vec)