From 32c1e5e4ae5d4e67359293d022ce1813d97d0119 Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Thu, 7 Nov 2019 11:14:18 -0600 Subject: [PATCH] Upgrade traits to futures 0.3 --- Cargo.toml | 14 ++++++-------- benches/pipe.rs | 15 +++++---------- src/pipe/chunked.rs | 2 +- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd5e443..cd9302f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sluice" -version = "0.4.2" +version = "0.5.0" authors = ["Stephen M. Coakley "] edition = "2018" description = "Efficient ring buffer for byte buffers, FIFO queues, and SPSC channels" @@ -11,17 +11,15 @@ keywords = ["buffer", "pipe", "channel"] categories = ["asynchronous", "concurrency", "data-structures"] license = "MIT" -[features] -nightly = [] - [dependencies] -futures-channel-preview = "0.3.0-alpha.18" -futures-core-preview = "0.3.0-alpha.18" -futures-io-preview = "0.3.0-alpha.18" +futures-channel = "0.3" +futures-core = "0.3" +futures-io = "0.3" +futures-util = "0.3" [dev-dependencies] criterion = "0.3" -futures-preview = "0.3.0-alpha.18" +futures = "0.3" [[bench]] name = "pipe" diff --git a/benches/pipe.rs b/benches/pipe.rs index 985bf0a..32a3e92 100644 --- a/benches/pipe.rs +++ b/benches/pipe.rs @@ -1,32 +1,27 @@ -#![cfg(feature = "nightly")] -#![feature(async_await)] - use criterion::*; fn benchmark(c: &mut Criterion) { c.bench_function("write 100 1K chunks", |b| { - use futures::executor::ThreadPool; use futures::prelude::*; - let mut pool = ThreadPool::new().unwrap(); let data = [1; 1024]; b.iter_batched( sluice::pipe::pipe, - |(mut reader, mut writer)| { + |(reader, mut writer)| { let producer = async { - for _ in 0..100 { + for _ in 0u8..100 { writer.write_all(&data).await.unwrap(); } writer.close().await.unwrap(); }; let consumer = async { - let mut sink = std::io::sink(); - reader.copy_into(&mut sink).await.unwrap(); + let mut sink = futures::io::sink(); + futures::io::copy(reader, &mut sink).await.unwrap(); }; - pool.run(future::join(producer, consumer)); + futures::executor::block_on(future::join(producer, consumer)); }, BatchSize::SmallInput, ) diff --git a/src/pipe/chunked.rs b/src/pipe/chunked.rs index 5701aec..e8e2f99 100644 --- a/src/pipe/chunked.rs +++ b/src/pipe/chunked.rs @@ -23,9 +23,9 @@ use futures_channel::mpsc; use futures_core::{FusedStream, Stream}; use futures_io::{AsyncRead, AsyncWrite}; +use futures_util::io::Cursor; use std::{ io, - io::Cursor, pin::Pin, task::{Context, Poll}, };