From f75434373e072bd06347b2bf60b070038291ecb6 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 16 Jan 2019 11:47:26 -0800 Subject: [PATCH 1/2] These "extern crate"s aren't needed in rust 2018 Change-Id: Ice7442b02e00b119058e2bc1460371a0a6c1f495 --- tests/integration.rs | 5 +---- tests/simple_example.rs | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index ed63c04d..c59fce66 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,7 +1,4 @@ -#[macro_use] -extern crate maplit; -extern crate tuf; - +use maplit::hashset; use tuf::crypto::{HashAlgorithm, PrivateKey, SignatureScheme}; use tuf::interchange::Json; use tuf::metadata::{ diff --git a/tests/simple_example.rs b/tests/simple_example.rs index 3a43b4c1..6ec72a0d 100644 --- a/tests/simple_example.rs +++ b/tests/simple_example.rs @@ -1,9 +1,5 @@ #![feature(async_await, await_macro, futures_api)] -extern crate chrono; -extern crate futures; -extern crate tuf; - use futures::executor::block_on; use tuf::client::{Client, Config, PathTranslator}; use tuf::crypto::{HashAlgorithm, KeyId, PrivateKey, SignatureScheme}; From 56fec88a75578cddee8158429fbac34ca9bd4ade Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 16 Jan 2019 12:05:55 -0800 Subject: [PATCH 2/2] Use latest nightly and futures-preview Change-Id: I4d2568eea455ce4b1d12e86650c6af154773f60c --- .travis.yml | 2 +- Cargo.toml | 2 +- appveyor.yml | 4 +- src/into_async_read.rs | 93 ------------------------------------------ src/lib.rs | 1 - src/repository.rs | 5 +-- 6 files changed, 6 insertions(+), 101 deletions(-) delete mode 100644 src/into_async_read.rs diff --git a/.travis.yml b/.travis.yml index e58355c5..6f98dd7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ dist: trusty language: rust cache: cargo rust: - - nightly-2019-01-09 + - nightly env: global: diff --git a/Cargo.toml b/Cargo.toml index 46d49006..6ac66acc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ path = "./src/lib.rs" chrono = { version = "0.4", features = [ "serde" ] } data-encoding = "2.0.0-rc.2" derp = "0.0.11" -futures-preview = { version = "0.3.0-alpha.11", features = [ "compat" ] } +futures-preview = { version = "0.3.0-alpha.12", features = [ "compat" ] } http = "0.1" hyper = { version = "0.12", default-features = false } itoa = "0.4" diff --git a/appveyor.yml b/appveyor.yml index 87a08fde..0348f0d2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,11 +12,11 @@ environment: matrix: # Rust - Nightly - TARGET: i686-pc-windows-gnu - RUST_VERSION: nightly-2019-01-09 + RUST_VERSION: nightly BITS: 32 MSYS2: 1 - TARGET: x86_64-pc-windows-msvc - RUST_VERSION: nightly-2019-01-09 + RUST_VERSION: nightly BITS: 64 install: diff --git a/src/into_async_read.rs b/src/into_async_read.rs deleted file mode 100644 index 18ce7c70..00000000 --- a/src/into_async_read.rs +++ /dev/null @@ -1,93 +0,0 @@ -// FIXME: remove once https://github.com/rust-lang-nursery/futures-rs/pull/1367 lands in a release. - -use futures::io::AsyncRead; -use futures::ready; -use futures::stream::TryStream; -use futures::task::{LocalWaker, Poll}; -use std::cmp; -use std::io::{Error, Result}; -use std::marker::Unpin; -use std::pin::Pin; - -pub struct IntoAsyncRead -where - St: TryStream + Unpin, - St::Ok: AsRef<[u8]>, -{ - stream: St, - state: ReadState, -} - -impl Unpin for IntoAsyncRead -where - St: TryStream + Unpin, - St::Ok: AsRef<[u8]>, -{ -} - -#[derive(Debug)] -enum ReadState> { - Ready { chunk: T, chunk_start: usize }, - PendingChunk, - Eof, -} - -impl IntoAsyncRead -where - St: TryStream + Unpin, - St::Ok: AsRef<[u8]>, -{ - pub(super) fn new(stream: St) -> Self { - IntoAsyncRead { - stream, - state: ReadState::PendingChunk, - } - } -} - -impl AsyncRead for IntoAsyncRead -where - St: TryStream + Unpin, - St::Ok: AsRef<[u8]>, -{ - fn poll_read(&mut self, lw: &LocalWaker, buf: &mut [u8]) -> Poll> { - loop { - match &mut self.state { - ReadState::Ready { chunk, chunk_start } => { - let chunk = chunk.as_ref(); - let len = cmp::min(buf.len(), chunk.len() - *chunk_start); - - buf[..len].copy_from_slice(&chunk[*chunk_start..*chunk_start + len]); - *chunk_start += len; - - if chunk.len() == *chunk_start { - self.state = ReadState::PendingChunk; - } - - return Poll::Ready(Ok(len)); - } - ReadState::PendingChunk => { - match ready!(Pin::new(&mut self.stream).try_poll_next(lw)) { - Some(Ok(chunk)) => { - self.state = ReadState::Ready { - chunk, - chunk_start: 0, - }; - continue; - } - Some(Err(err)) => { - return Poll::Ready(Err(err)); - } - None => { - self.state = ReadState::Eof; - return Poll::Ready(Ok(0)); - } - } - } - ReadState::Eof => { - return Poll::Ready(Ok(0)); - } - } - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 2d0585b2..45cfd0ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,7 +119,6 @@ pub mod metadata; pub mod repository; pub mod tuf; -mod into_async_read; mod shims; mod util; diff --git a/src/repository.rs b/src/repository.rs index dfa68ba9..6cb94a34 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -20,7 +20,6 @@ use tempfile::{self, NamedTempFile}; use crate::crypto::{self, HashAlgorithm, HashValue}; use crate::error::Error; use crate::interchange::DataInterchange; -use crate::into_async_read::IntoAsyncRead; use crate::metadata::{ Metadata, MetadataPath, MetadataVersion, SignedMetadata, TargetDescription, TargetPath, }; @@ -438,7 +437,7 @@ where .map_err(|err| io::Error::new(io::ErrorKind::Other, err)); let mut reader = SafeReader::new( - IntoAsyncRead::new(stream), + stream.into_async_read(), max_size.unwrap_or(::std::usize::MAX) as u64, self.min_bytes_per_second, hash_data, @@ -477,7 +476,7 @@ where .map_err(|err| io::Error::new(io::ErrorKind::Other, err)); let reader = SafeReader::new( - IntoAsyncRead::new(stream), + stream.into_async_read(), target_description.size(), self.min_bytes_per_second, Some((alg, value.clone())),