diff --git a/volo-thrift/src/codec/default/framed.rs b/volo-thrift/src/codec/default/framed.rs index 65e8c939..9fa94e79 100644 --- a/volo-thrift/src/codec/default/framed.rs +++ b/volo-thrift/src/codec/default/framed.rs @@ -74,7 +74,6 @@ impl FramedDecoder { /// https://github.com/apache/thrift/blob/master/doc/specs/thrift-rpc.md#compatibility pub const HEADER_DETECT_LENGTH: usize = 6; -#[async_trait::async_trait] impl ZeroCopyDecoder for FramedDecoder where D: ZeroCopyDecoder, diff --git a/volo-thrift/src/codec/default/mod.rs b/volo-thrift/src/codec/default/mod.rs index 6d14a6ca..9987d026 100644 --- a/volo-thrift/src/codec/default/mod.rs +++ b/volo-thrift/src/codec/default/mod.rs @@ -26,6 +26,8 @@ //! [Kitex]: https://github.com/cloudwego/kitex //! [TTHeader]: https://www.cloudwego.io/docs/kitex/reference/transport_protocol_ttheader/ //! [Framed]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-rpc.md#framed-vs-unframed-transport +use std::future::Future; + use bytes::Bytes; use linkedbytes::LinkedBytes; use pilota::thrift::{DecodeError, EncodeError, TransportError}; @@ -73,7 +75,6 @@ pub trait ZeroCopyEncoder: Send + Sync + 'static { /// [`ZeroCopyDecoder`] tries to decode a message without copying large data, so the [`Bytes`] in /// the [`decode`] method is not designed to be reused, and the implementation can use /// `Bytes::split_to` to get a [`Bytes`] and hand it to the user directly. -#[async_trait::async_trait] pub trait ZeroCopyDecoder: Send + Sync + 'static { /// If the outer decoder is framed, it can reads all the payload into a [`Bytes`] and /// call this function for better performance. @@ -85,7 +86,7 @@ pub trait ZeroCopyDecoder: Send + Sync + 'static { /// The [`DefaultDecoder`] will always call `decode_async`, so the most outer decoder /// must implement this function. - async fn decode_async< + fn decode_async< Msg: Send + EntryMessage, Cx: ThriftContext, R: AsyncRead + Unpin + Send + Sync, @@ -93,7 +94,7 @@ pub trait ZeroCopyDecoder: Send + Sync + 'static { &mut self, cx: &mut Cx, reader: &mut BufReader, - ) -> Result>, DecodeError>; + ) -> impl Future>, DecodeError>> + Send; } /// [`MakeZeroCopyCodec`] is used to create a [`ZeroCopyEncoder`] and a [`ZeroCopyDecoder`]. @@ -112,7 +113,6 @@ pub struct DefaultEncoder { linked_bytes: LinkedBytes, } -#[async_trait::async_trait] impl Encoder for DefaultEncoder { @@ -184,7 +184,6 @@ pub struct DefaultDecoder { reader: BufReader, } -#[async_trait::async_trait] impl Decoder for DefaultDecoder { diff --git a/volo-thrift/src/codec/default/thrift.rs b/volo-thrift/src/codec/default/thrift.rs index a3cdb046..a94f735a 100644 --- a/volo-thrift/src/codec/default/thrift.rs +++ b/volo-thrift/src/codec/default/thrift.rs @@ -104,7 +104,6 @@ impl Default for ThriftCodec { } } -#[async_trait::async_trait] impl ZeroCopyDecoder for ThriftCodec { #[inline] fn decode( diff --git a/volo-thrift/src/codec/default/ttheader.rs b/volo-thrift/src/codec/default/ttheader.rs index 3c3ec27c..fbbcc42c 100644 --- a/volo-thrift/src/codec/default/ttheader.rs +++ b/volo-thrift/src/codec/default/ttheader.rs @@ -70,7 +70,6 @@ impl TTHeaderDecoder { /// https://www.cloudwego.io/docs/kitex/reference/transport_protocol_ttheader/ pub const HEADER_DETECT_LENGTH: usize = 6; -#[async_trait::async_trait] impl ZeroCopyDecoder for TTHeaderDecoder where D: ZeroCopyDecoder, diff --git a/volo-thrift/src/codec/mod.rs b/volo-thrift/src/codec/mod.rs index e7454c4e..93118cb4 100644 --- a/volo-thrift/src/codec/mod.rs +++ b/volo-thrift/src/codec/mod.rs @@ -1,3 +1,5 @@ +use std::future::Future; + use tokio::io::{AsyncRead, AsyncWrite}; use crate::{context::ThriftContext, EntryMessage, ThriftMessage}; @@ -12,24 +14,22 @@ pub use default::DefaultMakeCodec; /// Returning an Ok(None) indicates the EOF has been reached. /// /// Note: [`Decoder`] should be designed to be ready for reuse. -#[async_trait::async_trait] pub trait Decoder: Send + 'static { - async fn decode( + fn decode( &mut self, cx: &mut Cx, - ) -> Result>, crate::Error>; + ) -> impl Future>, crate::Error>> + Send; } /// [`Encoder`] writes a [`ThriftMessage`] to an [`AsyncWrite`] and flushes the data. /// /// Note: [`Encoder`] should be designed to be ready for reuse. -#[async_trait::async_trait] pub trait Encoder: Send + 'static { - async fn encode( + fn encode( &mut self, cx: &mut Cx, msg: ThriftMessage, - ) -> Result<(), crate::Error>; + ) -> impl Future> + Send; } /// [`MakeCodec`] receives an [`AsyncRead`] and an [`AsyncWrite`] and returns a