diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..219c13a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..ff2a597 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,107 @@ +on: [push, pull_request] + +name: Continuous integration + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # Caching + - name: Cache cargo registry + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: cargo-registry-${{ hashFiles('Cargo.toml') }} + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: cargo-index-${{ hashFiles('Cargo.toml') }} + + - uses: actions-rs/cargo@v1 + with: + command: check + args: --all --all-features + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # Caching + - name: Cache cargo registry + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: cargo-registry-${{ hashFiles('Cargo.toml') }} + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: cargo-index-${{ hashFiles('Cargo.toml') }} + + - uses: actions-rs/cargo@v1 + with: + command: test + args: --all --all-features + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + continue-on-error: true + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - run: rustup component add clippy + + # Caching + - name: Cache cargo registry + uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: cargo-registry-${{ hashFiles('Cargo.toml') }} + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: cargo-index-${{ hashFiles('Cargo.toml') }} + + - uses: actions-rs/cargo@v1 + continue-on-error: true + with: + command: clippy + args: -- -D warnings diff --git a/Cargo.toml b/Cargo.toml index 551187d..a514123 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "futures_codec" +name = "asynchronous-codec" edition = "2018" -version = "0.4.1" -authors = ["Matt Hunzinger "] +version = "0.5.0" +authors = ["Max Inden "] description = "Utilities for encoding and decoding frames using `async/await`" license = "MIT" readme = "README.md" -repository = "https://github.com/matthunz/futures-codec" -homepage = "https://github.com/matthunz/futures-codec" -documentation = "https://docs.rs/crate/futures_codec" +repository = "https://github.com/mxinden/asynchronous-codec" +homepage = "https://github.com/mxinden/asynchronous-codec" +documentation = "https://docs.rs/crate/asynchronous-codec" keywords = ["future", "futures", "async", "codec"] categories = ["asynchronous", "network-programming"] @@ -18,22 +18,26 @@ json = [ "serde", "serde_json" ] cbor = [ "serde", "serde_cbor" ] [dependencies] -bytes = "0.5.4" -futures = "0.3.5" -memchr = "2.2.3" -pin-project = "0.4.22" +bytes = "1" +futures-sink = "0.3" +futures-util = { version = "0.3", features = ["io"] } +memchr = "2" +pin-project-lite = "0.2" + +[dev-dependencies] +futures = "0.3" [dependencies.serde] -version = '1.0.113' +version = "1" optional = true features = [ "derive" ] [dependencies.serde_json] -version = '1.0.55' +version = "1" optional = true [dependencies.serde_cbor] -version = '0.11.1' +version = "0.11" optional = true [package.metadata.docs.rs] diff --git a/LICENSE b/LICENSE index ed316a7..513d2d2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2019 Matt Hunzinger +Copyright (c) 2019 - 2020 Matt Hunzinger +Copyright (c) 2021 Max Inden Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3ff2b0a..e6a8cf8 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,23 @@ -# futures_codec +# Asynchronous Codec Utilities for encoding and decoding frames using async/await. +This is a fork of [`futures-codec`](https://github.com/matthunz/futures-codec) +by [Matt Hunzinger](https://github.com/matthunz) borrowing many concepts from +[`tokio-codec`](https://crates.io/crates/tokio-codec). + Contains adapters to go from streams of bytes, `AsyncRead` and `AsyncWrite`, to framed streams implementing `Sink` and `Stream`. Framed streams are also known as transports. -[![Latest Version](https://img.shields.io/crates/v/futures-codec.svg)](https://crates.io/crates/futures-codec) -[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/futures-codec) -[![Build Status](https://travis-ci.com/matthunz/futures-codec.svg)](https://travis-ci.com/matthunz/futures-codec) +[![Latest Version](https://img.shields.io/crates/v/asynchronous-codec.svg)](https://crates.io/crates/asynchronous-codec) +[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/asynchronous-codec) ![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg) ### Example + ```rust -use futures_codec::{LinesCodec, Framed}; +use asynchronous_codec::{LinesCodec, Framed}; async fn main() { // let stream = ... diff --git a/benches/lines.rs b/benches/lines.rs index 99e3b11..a442902 100644 --- a/benches/lines.rs +++ b/benches/lines.rs @@ -2,9 +2,8 @@ extern crate test; -use futures::{executor, TryStreamExt}; -use futures_codec::{FramedRead, LinesCodec}; -use std::io::Cursor; +use asynchronous_codec::{FramedRead, LinesCodec}; +use futures::{executor, io::Cursor, TryStreamExt}; #[bench] fn short(b: &mut test::Bencher) { diff --git a/src/codec/bytes.rs b/src/codec/bytes.rs index 82e8e2f..6bcca2f 100644 --- a/src/codec/bytes.rs +++ b/src/codec/bytes.rs @@ -11,7 +11,7 @@ use std::io::Error; /// use bytes::Bytes; /// use futures::{SinkExt, TryStreamExt}; /// use futures::io::Cursor; -/// use futures_codec::{BytesCodec, Framed}; +/// use asynchronous_codec::{BytesCodec, Framed}; /// /// let mut buf = vec![]; /// // Cursor implements AsyncRead and AsyncWrite diff --git a/src/codec/cbor.rs b/src/codec/cbor.rs index 76cc71f..ef781aa 100644 --- a/src/codec/cbor.rs +++ b/src/codec/cbor.rs @@ -13,7 +13,7 @@ use serde_cbor::Error as CborError; /// # use futures::{executor, SinkExt, TryStreamExt}; /// # use futures::io::Cursor; /// use serde::{Serialize, Deserialize}; -/// use futures_codec::{CborCodec, Framed}; +/// use asynchronous_codec::{CborCodec, Framed}; /// /// #[derive(Serialize, Deserialize)] /// struct Something { @@ -47,15 +47,33 @@ pub enum CborCodecError { Cbor(CborError), } +impl std::fmt::Display for CborCodecError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CborCodecError::Io(e) => write!(f, "I/O error: {}", e), + CborCodecError::Cbor(e) => write!(f, "CBOR error: {}", e), + } + } +} + +impl std::error::Error for CborCodecError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + CborCodecError::Io(ref e) => Some(e), + CborCodecError::Cbor(ref e) => Some(e), + } + } +} + impl From for CborCodecError { fn from(e: IoError) -> CborCodecError { - return CborCodecError::Io(e); + CborCodecError::Io(e) } } impl From for CborCodecError { fn from(e: CborError) -> CborCodecError { - return CborCodecError::Cbor(e); + CborCodecError::Cbor(e) } } @@ -138,6 +156,16 @@ where } } +impl Default for CborCodec +where + for<'de> Dec: Deserialize<'de> + 'static, + for<'de> Enc: Serialize + 'static, +{ + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod test { use bytes::BytesMut; @@ -180,7 +208,7 @@ mod test { name: "Test name".to_owned(), data: 34, }; - codec.encode(item1.clone(), &mut buff).unwrap(); + codec.encode(item1, &mut buff).unwrap(); let mut start = buff.clone().split_to(4); assert_eq!(codec.decode(&mut start).unwrap(), None); diff --git a/src/codec/json.rs b/src/codec/json.rs index 933efe3..10a2583 100644 --- a/src/codec/json.rs +++ b/src/codec/json.rs @@ -4,7 +4,6 @@ use crate::{Decoder, Encoder}; use bytes::{Buf, BufMut, BytesMut}; use serde::{Deserialize, Serialize}; -use serde_json; /// A codec for JSON encoding and decoding using serde_json /// Enc is the type to encode, Dec is the type to decode @@ -12,7 +11,7 @@ use serde_json; /// # use futures::{executor, SinkExt, TryStreamExt}; /// # use futures::io::Cursor; /// use serde::{Serialize, Deserialize}; -/// use futures_codec::{JsonCodec, Framed}; +/// use asynchronous_codec::{JsonCodec, Framed}; /// /// #[derive(Serialize, Deserialize)] /// struct Something { @@ -46,15 +45,33 @@ pub enum JsonCodecError { Json(serde_json::Error), } +impl std::fmt::Display for JsonCodecError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + JsonCodecError::Io(e) => write!(f, "I/O error: {}", e), + JsonCodecError::Json(e) => write!(f, "JSON error: {}", e), + } + } +} + +impl std::error::Error for JsonCodecError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + JsonCodecError::Io(ref e) => Some(e), + JsonCodecError::Json(ref e) => Some(e), + } + } +} + impl From for JsonCodecError { fn from(e: std::io::Error) -> JsonCodecError { - return JsonCodecError::Io(e); + JsonCodecError::Io(e) } } impl From for JsonCodecError { fn from(e: serde_json::Error) -> JsonCodecError { - return JsonCodecError::Json(e); + JsonCodecError::Json(e) } } @@ -136,6 +153,16 @@ where } } +impl Default for JsonCodec +where + for<'de> Dec: Deserialize<'de> + 'static, + for<'de> Enc: Serialize + 'static, +{ + fn default() -> Self { + Self::new() + } +} + #[cfg(test)] mod test { use bytes::BytesMut; @@ -178,7 +205,7 @@ mod test { name: "Test name".to_owned(), data: 34, }; - codec.encode(item1.clone(), &mut buff).unwrap(); + codec.encode(item1, &mut buff).unwrap(); let mut start = buff.clone().split_to(4); assert_eq!(codec.decode(&mut start).unwrap(), None); diff --git a/src/codec/length.rs b/src/codec/length.rs index 2c0a90a..344f6b6 100644 --- a/src/codec/length.rs +++ b/src/codec/length.rs @@ -11,7 +11,7 @@ const U64_LENGTH: usize = std::mem::size_of::(); /// This codec will most likely be used wrapped in another codec like so. /// /// ``` -/// use futures_codec::{Decoder, Encoder, LengthCodec}; +/// use asynchronous_codec::{Decoder, Encoder, LengthCodec}; /// use bytes::{Bytes, BytesMut}; /// use std::io::{Error, ErrorKind}; /// diff --git a/src/codec/lines.rs b/src/codec/lines.rs index 5c6540f..f8bd823 100644 --- a/src/codec/lines.rs +++ b/src/codec/lines.rs @@ -8,7 +8,7 @@ use std::io::{Error, ErrorKind}; /// ```rust /// # futures::executor::block_on(async move { /// use futures::stream::TryStreamExt; // for lines.try_next() -/// use futures_codec::{FramedRead, LinesCodec}; +/// use asynchronous_codec::{FramedRead, LinesCodec}; /// /// let input = "hello\nworld\nthis\nis\ndog\n".as_bytes(); /// let mut lines = FramedRead::new(input, LinesCodec); diff --git a/src/framed.rs b/src/framed.rs index 521ab58..119437a 100644 --- a/src/framed.rs +++ b/src/framed.rs @@ -3,43 +3,45 @@ use super::framed_write::{framed_write_2, FramedWrite2}; use super::fuse::Fuse; use super::{Decoder, Encoder}; use bytes::BytesMut; -use futures::io::{AsyncRead, AsyncWrite}; -use futures::{Sink, Stream, TryStreamExt}; -use pin_project::pin_project; +use futures_sink::Sink; +use futures_util::io::{AsyncRead, AsyncWrite}; +use futures_util::stream::{Stream, TryStreamExt}; +use pin_project_lite::pin_project; use std::marker::Unpin; use std::ops::{Deref, DerefMut}; use std::pin::Pin; use std::task::{Context, Poll}; -/// A unified `Stream` and `Sink` interface to an underlying I/O object, -/// using the `Encoder` and `Decoder` traits to encode and decode frames. -/// -/// # Example -/// ``` -/// use bytes::Bytes; -/// use futures::{SinkExt, TryStreamExt}; -/// use futures::io::Cursor; -/// use futures_codec::{BytesCodec, Framed}; -/// -/// # futures::executor::block_on(async move { -/// let cur = Cursor::new(vec![0u8; 12]); -/// let mut framed = Framed::new(cur, BytesCodec {}); -/// -/// // Send bytes to `buf` through the `BytesCodec` -/// let bytes = Bytes::from("Hello world!"); -/// framed.send(bytes).await?; -/// -/// // Drop down to the underlying I/O stream. -/// let cur = framed.into_inner(); -/// assert_eq!(cur.get_ref(), b"Hello world!"); -/// # Ok::<_, std::io::Error>(()) -/// # }).unwrap(); -/// ``` -#[pin_project] -#[derive(Debug)] -pub struct Framed { - #[pin] - inner: FramedRead2>>, +pin_project! { + /// A unified `Stream` and `Sink` interface to an underlying I/O object, + /// using the `Encoder` and `Decoder` traits to encode and decode frames. + /// + /// # Example + /// ``` + /// use bytes::Bytes; + /// use futures::{SinkExt, TryStreamExt}; + /// use futures::io::Cursor; + /// use asynchronous_codec::{BytesCodec, Framed}; + /// + /// # futures::executor::block_on(async move { + /// let cur = Cursor::new(vec![0u8; 12]); + /// let mut framed = Framed::new(cur, BytesCodec {}); + /// + /// // Send bytes to `buf` through the `BytesCodec` + /// let bytes = Bytes::from("Hello world!"); + /// framed.send(bytes).await?; + /// + /// // Drop down to the underlying I/O stream. + /// let cur = framed.into_inner(); + /// assert_eq!(cur.get_ref(), b"Hello world!"); + /// # Ok::<_, std::io::Error>(()) + /// # }).unwrap(); + /// ``` + #[derive(Debug)] + pub struct Framed { + #[pin] + inner: FramedRead2>>, + } } impl Deref for Framed { @@ -72,9 +74,15 @@ where /// Creates a new `Framed` from [`FramedParts`]. /// /// See also [`Framed::into_parts`]. - pub fn from_parts(FramedParts { - io, codec, write_buffer, read_buffer, .. - }: FramedParts) -> Self { + pub fn from_parts( + FramedParts { + io, + codec, + write_buffer, + read_buffer, + .. + }: FramedParts, + ) -> Self { let framed_write = framed_write_2(Fuse::new(io, codec), Some(write_buffer)); let framed_read = framed_read_2(framed_write, Some(read_buffer)); Self { inner: framed_read } diff --git a/src/framed_read.rs b/src/framed_read.rs index b5e3fd9..1eb4317 100644 --- a/src/framed_read.rs +++ b/src/framed_read.rs @@ -2,9 +2,11 @@ use super::fuse::Fuse; use super::Decoder; use bytes::BytesMut; -use futures::io::AsyncRead; -use futures::{ready, Sink, Stream, TryStreamExt}; -use pin_project::pin_project; +use futures_sink::Sink; +use futures_util::io::AsyncRead; +use futures_util::ready; +use futures_util::stream::{Stream, TryStreamExt}; +use pin_project_lite::pin_project; use std::io; use std::marker::Unpin; use std::ops::{Deref, DerefMut}; @@ -15,7 +17,7 @@ use std::task::{Context, Poll}; /// /// # Example /// ``` -/// use futures_codec::{BytesCodec, FramedRead}; +/// use asynchronous_codec::{BytesCodec, FramedRead}; /// use futures::TryStreamExt; /// use bytes::{Bytes}; /// @@ -63,11 +65,16 @@ where /// Creates a new `FramedRead` from [`FramedReadParts`]. /// /// See also [`FramedRead::into_parts`]. - pub fn from_parts(FramedReadParts { - io, decoder, buffer, .. - }: FramedReadParts) -> Self { + pub fn from_parts( + FramedReadParts { + io, + decoder, + buffer, + .. + }: FramedReadParts, + ) -> Self { Self { - inner: framed_read_2(Fuse::new(io, decoder), Some(buffer)) + inner: framed_read_2(Fuse::new(io, decoder), Some(buffer)), } } @@ -128,12 +135,13 @@ where } } -#[pin_project] -#[derive(Debug)] -pub struct FramedRead2 { - #[pin] - inner: T, - buffer: BytesMut, +pin_project! { + #[derive(Debug)] + pub struct FramedRead2 { + #[pin] + inner: T, + buffer: BytesMut, + } } impl Deref for FramedRead2 { diff --git a/src/framed_write.rs b/src/framed_write.rs index f11815f..012c660 100644 --- a/src/framed_write.rs +++ b/src/framed_write.rs @@ -1,39 +1,41 @@ use super::fuse::Fuse; use super::Encoder; use bytes::{Buf, BytesMut}; -use futures::io::{AsyncRead, AsyncWrite}; -use futures::{ready, Sink}; -use pin_project::pin_project; +use futures_sink::Sink; +use futures_util::io::{AsyncRead, AsyncWrite}; +use futures_util::ready; +use pin_project_lite::pin_project; use std::io::{Error, ErrorKind}; use std::marker::Unpin; use std::ops::{Deref, DerefMut}; use std::pin::Pin; use std::task::{Context, Poll}; -/// A `Sink` of frames encoded to an `AsyncWrite`. -/// -/// # Example -/// ``` -/// use bytes::Bytes; -/// use futures_codec::{FramedWrite, BytesCodec}; -/// use futures::SinkExt; -/// -/// # futures::executor::block_on(async move { -/// let mut buf = Vec::new(); -/// let mut framed = FramedWrite::new(&mut buf, BytesCodec {}); -/// -/// let bytes = Bytes::from("Hello World!"); -/// framed.send(bytes.clone()).await?; -/// -/// assert_eq!(&buf[..], &bytes[..]); -/// # Ok::<_, std::io::Error>(()) -/// # }).unwrap(); -/// ``` -#[pin_project] -#[derive(Debug)] -pub struct FramedWrite { - #[pin] - inner: FramedWrite2>, +pin_project! { + /// A `Sink` of frames encoded to an `AsyncWrite`. + /// + /// # Example + /// ``` + /// use bytes::Bytes; + /// use asynchronous_codec::{FramedWrite, BytesCodec}; + /// use futures::SinkExt; + /// + /// # futures::executor::block_on(async move { + /// let mut buf = Vec::new(); + /// let mut framed = FramedWrite::new(&mut buf, BytesCodec {}); + /// + /// let bytes = Bytes::from("Hello World!"); + /// framed.send(bytes.clone()).await?; + /// + /// assert_eq!(&buf[..], &bytes[..]); + /// # Ok::<_, std::io::Error>(()) + /// # }).unwrap(); + /// ``` + #[derive(Debug)] + pub struct FramedWrite { + #[pin] + inner: FramedWrite2>, + } } impl FramedWrite @@ -51,11 +53,16 @@ where /// Creates a new `FramedWrite` from [`FramedWriteParts`]. /// /// See also [`FramedWrite::into_parts`]. - pub fn from_parts(FramedWriteParts { - io, encoder, buffer, .. - }: FramedWriteParts) -> Self { + pub fn from_parts( + FramedWriteParts { + io, + encoder, + buffer, + .. + }: FramedWriteParts, + ) -> Self { Self { - inner: framed_write_2(Fuse::new(io, encoder), Some(buffer)) + inner: framed_write_2(Fuse::new(io, encoder), Some(buffer)), } } @@ -71,7 +78,7 @@ where /// /// See [`set_send_high_water_mark()`](#method.set_send_high_water_mark). pub fn send_high_water_mark(&self) -> usize { - return self.inner.high_water_mark; + self.inner.high_water_mark } /// Sets high-water mark for writes, in bytes @@ -168,13 +175,14 @@ impl DerefMut for FramedWrite { } } -#[pin_project] -#[derive(Debug)] -pub struct FramedWrite2 { - #[pin] - pub inner: T, - pub high_water_mark: usize, - buffer: BytesMut, +pin_project! { + #[derive(Debug)] + pub struct FramedWrite2 { + #[pin] + pub inner: T, + pub high_water_mark: usize, + buffer: BytesMut, + } } impl Deref for FramedWrite2 { diff --git a/src/fuse.rs b/src/fuse.rs index 8027e4e..ee015d2 100644 --- a/src/fuse.rs +++ b/src/fuse.rs @@ -1,17 +1,18 @@ -use futures::io::{AsyncRead, AsyncWrite}; -use pin_project::pin_project; +use futures_util::io::{AsyncRead, AsyncWrite}; +use pin_project_lite::pin_project; use std::io::Error; use std::marker::Unpin; use std::ops::{Deref, DerefMut}; use std::pin::Pin; use std::task::{Context, Poll}; -#[pin_project] -#[derive(Debug)] -pub(crate) struct Fuse { - #[pin] - pub t: T, - pub u: U, +pin_project! { + #[derive(Debug)] + pub(crate) struct Fuse { + #[pin] + pub t: T, + pub u: U, + } } impl Fuse { diff --git a/src/lib.rs b/src/lib.rs index eb20aef..d52f231 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ //! # futures::executor::block_on(async move { //! use futures::TryStreamExt; //! use futures::io::Cursor; -//! use futures_codec::{LinesCodec, Framed}; +//! use asynchronous_codec::{LinesCodec, Framed}; //! //! let io = Cursor::new(Vec::new()); //! let mut framed = Framed::new(io, LinesCodec); @@ -22,8 +22,8 @@ //! ``` mod codec; -pub use codec::{BytesCodec, LengthCodec, LinesCodec}; pub use bytes::{Bytes, BytesMut}; +pub use codec::{BytesCodec, LengthCodec, LinesCodec}; #[cfg(feature = "cbor")] pub use codec::{CborCodec, CborCodecError}; diff --git a/tests/bytes.rs b/tests/bytes.rs index f2bf40b..98f3ba3 100644 --- a/tests/bytes.rs +++ b/tests/bytes.rs @@ -1,11 +1,11 @@ +use asynchronous_codec::{BytesCodec, Framed}; use futures::io::Cursor; use futures::{executor, TryStreamExt}; -use futures_codec::{BytesCodec, Framed}; #[test] fn decodes() { let mut buf = [0u8; 32]; - let expected = buf.clone(); + let expected = buf; let cur = Cursor::new(&mut buf[..]); let mut framed = Framed::new(cur, BytesCodec {}); diff --git a/tests/framed_read.rs b/tests/framed_read.rs index 025779a..e873f08 100644 --- a/tests/framed_read.rs +++ b/tests/framed_read.rs @@ -1,7 +1,7 @@ +use asynchronous_codec::{BytesMut, Decoder, FramedRead, LinesCodec}; use futures::executor; use futures::stream::StreamExt; use futures::AsyncRead; -use futures_codec::{Decoder, FramedRead, LinesCodec, BytesMut}; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; @@ -16,7 +16,7 @@ impl AsyncRead for MockBurstySender { _cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { - const MESSAGES: &'static [u8] = b"one\ntwo\n"; + const MESSAGES: &[u8] = b"one\ntwo\n"; if !self.sent && buf.len() >= MESSAGES.len() { self.sent = true; buf[0..MESSAGES.len()].clone_from_slice(MESSAGES); diff --git a/tests/framed_write.rs b/tests/framed_write.rs index 918fc07..77bc6d8 100644 --- a/tests/framed_write.rs +++ b/tests/framed_write.rs @@ -1,8 +1,8 @@ +use asynchronous_codec::{Bytes, BytesCodec, FramedWrite, LinesCodec}; use core::iter::Iterator; use futures::io::{AsyncWrite, Cursor}; use futures::sink::SinkExt; use futures::{executor, stream, stream::StreamExt}; -use futures_codec::{BytesCodec, FramedWrite, LinesCodec, Bytes}; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/tests/length_delimited.rs b/tests/length_delimited.rs index 0b085ef..93a1a7e 100644 --- a/tests/length_delimited.rs +++ b/tests/length_delimited.rs @@ -1,6 +1,6 @@ +use asynchronous_codec::{Bytes, Framed, LengthCodec}; use futures::io::Cursor; use futures::{executor, SinkExt, StreamExt}; -use futures_codec::{Framed, LengthCodec, Bytes}; #[test] fn same_msgs_are_received_as_were_sent() { diff --git a/tests/lines.rs b/tests/lines.rs index b90f8a9..c12e983 100644 --- a/tests/lines.rs +++ b/tests/lines.rs @@ -1,6 +1,6 @@ +use asynchronous_codec::{FramedRead, LinesCodec}; use futures::io::Cursor; use futures::{executor, TryStreamExt}; -use futures_codec::{FramedRead, LinesCodec}; #[test] fn it_works() {