|
5 | 5 |
|
6 | 6 | use std::marker::PhantomData; |
7 | 7 |
|
8 | | -use compio_buf::{IoBufMut, bytes::Bytes}; |
| 8 | +use compio_buf::IoBufMut; |
9 | 9 | use futures_util::FutureExt; |
10 | 10 |
|
11 | 11 | use crate::{ |
12 | 12 | AsyncRead, |
13 | | - framed::{ |
14 | | - codec::{Decoder, bytes::BytesCodec}, |
15 | | - frame::NoopFramer, |
16 | | - }, |
| 13 | + framed::{codec::Decoder, frame::NoopFramer}, |
17 | 14 | util::Splittable, |
18 | 15 | }; |
19 | 16 |
|
@@ -151,17 +148,43 @@ impl<C, F> Framed<(), (), C, F, (), (), ()> { |
151 | 148 | } |
152 | 149 | } |
153 | 150 |
|
154 | | -/// A type alias for a `Framed` with bytes as the input and output type. |
155 | | -pub type BytesFramed<R, W> = Framed<R, W, BytesCodec, NoopFramer, Bytes, Bytes>; |
156 | | - |
| 151 | +/// [`Framed`] that bridges [`AsyncRead`]/[`AsyncWrite`] with [`Bytes`]. |
| 152 | +/// |
| 153 | +/// This is useful when you want to read/write raw bytes into/from [`Bytes`] |
| 154 | +/// without any additional framing or de/encoding. |
| 155 | +/// |
| 156 | +/// See also: [`ReaderStream`] and [`ReaderStream`]. |
| 157 | +/// |
| 158 | +/// [`Bytes`]: compio_buf::bytes::Bytes |
| 159 | +/// [`AsyncWrite`]: crate::AsyncWrite |
| 160 | +/// [`ReaderStream`]: https://docs.rs/tokio-util/latest/tokio_util/io/struct.ReaderStream.html |
| 161 | +/// [`StreamReader`]: https://docs.rs/tokio-util/latest/tokio_util/io/struct.StreamReader.html |
| 162 | +#[cfg(feature = "bytes")] |
| 163 | +pub type BytesFramed<R, W> = Framed< |
| 164 | + R, |
| 165 | + W, |
| 166 | + codec::bytes::BytesCodec, |
| 167 | + NoopFramer, |
| 168 | + compio_buf::bytes::Bytes, |
| 169 | + compio_buf::bytes::Bytes, |
| 170 | +>; |
| 171 | + |
| 172 | +#[cfg(feature = "bytes")] |
157 | 173 | impl BytesFramed<(), ()> { |
158 | | - /// Creates a new `Framed` with the given I/O object, codec, and framer with |
159 | | - /// bytes as the input and output type. |
| 174 | + /// Creates a new [`BytesFramed`] that bridges [`AsyncRead`]/[`AsyncWrite`] |
| 175 | + /// with [`Bytes`]. |
| 176 | + /// |
| 177 | + /// See also: [`ReaderStream`] and [`StreamReader`]. |
| 178 | + /// |
| 179 | + /// [`Bytes`]: compio_buf::bytes::Bytes |
| 180 | + /// [`AsyncWrite`]: crate::AsyncWrite |
| 181 | + /// [`ReaderStream`]: https://docs.rs/tokio-util/latest/tokio_util/io/struct.ReaderStream.html |
| 182 | + /// [`StreamReader`]: https://docs.rs/tokio-util/latest/tokio_util/io/struct.StreamReader.html |
160 | 183 | pub fn new_bytes() -> Self { |
161 | 184 | Framed { |
162 | 185 | read_state: read::State::empty(), |
163 | 186 | write_state: write::State::empty(), |
164 | | - codec: BytesCodec::new(), |
| 187 | + codec: codec::bytes::BytesCodec::new(), |
165 | 188 | framer: NoopFramer::new(), |
166 | 189 | types: PhantomData, |
167 | 190 | } |
|
0 commit comments