Update crate to Rust 2018 (#383)
This commit is contained in:
committed by
Sean McArthur
parent
b3351e675b
commit
db6b841e67
@@ -2,6 +2,7 @@
|
||||
name = "h2-support"
|
||||
version = "0.1.0"
|
||||
authors = ["Carl Lerche <me@carllerche.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
h2 = { path = "../..", features = ["unstable"] }
|
||||
|
||||
@@ -10,7 +10,7 @@ macro_rules! assert_closed {
|
||||
macro_rules! assert_headers {
|
||||
($frame:expr) => {{
|
||||
match $frame {
|
||||
::h2::frame::Frame::Headers(v) => v,
|
||||
h2::frame::Frame::Headers(v) => v,
|
||||
f => panic!("expected HEADERS; actual={:?}", f),
|
||||
}
|
||||
}}
|
||||
@@ -20,7 +20,7 @@ macro_rules! assert_headers {
|
||||
macro_rules! assert_data {
|
||||
($frame:expr) => {{
|
||||
match $frame {
|
||||
::h2::frame::Frame::Data(v) => v,
|
||||
h2::frame::Frame::Data(v) => v,
|
||||
f => panic!("expected DATA; actual={:?}", f),
|
||||
}
|
||||
}}
|
||||
@@ -30,7 +30,7 @@ macro_rules! assert_data {
|
||||
macro_rules! assert_ping {
|
||||
($frame:expr) => {{
|
||||
match $frame {
|
||||
::h2::frame::Frame::Ping(v) => v,
|
||||
h2::frame::Frame::Ping(v) => v,
|
||||
f => panic!("expected PING; actual={:?}", f),
|
||||
}
|
||||
}}
|
||||
@@ -40,7 +40,7 @@ macro_rules! assert_ping {
|
||||
macro_rules! assert_settings {
|
||||
($frame:expr) => {{
|
||||
match $frame {
|
||||
::h2::frame::Frame::Settings(v) => v,
|
||||
h2::frame::Frame::Settings(v) => v,
|
||||
f => panic!("expected SETTINGS; actual={:?}", f),
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
//! Utilities to support tests.
|
||||
|
||||
pub extern crate bytes;
|
||||
pub extern crate env_logger;
|
||||
#[macro_use]
|
||||
pub extern crate futures;
|
||||
pub extern crate h2;
|
||||
pub extern crate http;
|
||||
pub extern crate string;
|
||||
#[macro_use]
|
||||
pub extern crate tokio_io;
|
||||
|
||||
#[macro_use]
|
||||
mod assert;
|
||||
pub mod assert;
|
||||
|
||||
pub mod raw;
|
||||
|
||||
@@ -25,8 +15,8 @@ pub mod util;
|
||||
mod client_ext;
|
||||
mod future_ext;
|
||||
|
||||
pub use client_ext::{SendRequestExt};
|
||||
pub use future_ext::{FutureExt, Unwrap};
|
||||
pub use crate::client_ext::{SendRequestExt};
|
||||
pub use crate::future_ext::{FutureExt, Unwrap};
|
||||
|
||||
pub type WindowSize = usize;
|
||||
pub const DEFAULT_WINDOW_SIZE: WindowSize = (1 << 16) - 1;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use {frames, FutureExt, SendFrame};
|
||||
use crate::{frames, FutureExt, SendFrame};
|
||||
|
||||
use h2::{self, RecvError, SendError};
|
||||
use h2::frame::{self, Frame};
|
||||
@@ -22,7 +22,7 @@ pub struct Mock {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Handle {
|
||||
codec: ::Codec<Pipe>,
|
||||
codec: crate::Codec<Pipe>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -92,7 +92,7 @@ pub fn new_with_write_capacity(cap: usize) -> (Mock, Handle) {
|
||||
|
||||
impl Handle {
|
||||
/// Get a mutable reference to inner Codec.
|
||||
pub fn codec_mut(&mut self) -> &mut ::Codec<Pipe> {
|
||||
pub fn codec_mut(&mut self) -> &mut crate::Codec<Pipe> {
|
||||
&mut self.codec
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ impl io::Write for Handle {
|
||||
impl AsyncWrite for Handle {
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
use std::io::Write;
|
||||
try_nb!(self.flush());
|
||||
tokio_io::try_nb!(self.flush());
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,7 @@ impl io::Write for Mock {
|
||||
impl AsyncWrite for Mock {
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
use std::io::Write;
|
||||
try_nb!(self.flush());
|
||||
tokio_io::try_nb!(self.flush());
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
@@ -426,7 +426,7 @@ impl io::Write for Pipe {
|
||||
impl AsyncWrite for Pipe {
|
||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||
use std::io::Write;
|
||||
try_nb!(self.flush());
|
||||
tokio_io::try_nb!(self.flush());
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
@@ -519,7 +519,7 @@ pub trait HandleFutureExt {
|
||||
.write_buf(&mut buf)
|
||||
.map_err(|e| panic!("write err={:?}", e));
|
||||
|
||||
try_ready!(res);
|
||||
futures::try_ready!(res);
|
||||
}
|
||||
|
||||
Ok(handle.take().unwrap().into())
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//! Then use it in your project. For example, a test could be written:
|
||||
//!
|
||||
//! ```
|
||||
//! extern crate mock_io;
|
||||
//!
|
||||
//! use mock_io::{Builder, Mock};
|
||||
//! use std::io::{Read, Write};
|
||||
//!
|
||||
@@ -88,7 +86,7 @@ use std::time::{Duration, Instant};
|
||||
pub struct Mock {
|
||||
inner: Inner,
|
||||
tokio: tokio::Inner,
|
||||
async: Option<bool>,
|
||||
r#async: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -103,7 +101,7 @@ pub struct Builder {
|
||||
actions: VecDeque<Action>,
|
||||
|
||||
// true for Tokio, false for blocking, None to auto detect
|
||||
async: Option<bool>,
|
||||
r#async: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -171,7 +169,7 @@ impl Builder {
|
||||
waiting: None,
|
||||
},
|
||||
tokio: tokio,
|
||||
async: src.async,
|
||||
r#async: src.r#async,
|
||||
};
|
||||
|
||||
let handle = Handle { inner: handle };
|
||||
@@ -231,7 +229,7 @@ impl Mock {
|
||||
|
||||
/// Returns `true` if running in a futures-rs task context
|
||||
fn is_async(&self) -> bool {
|
||||
self.async.unwrap_or(tokio::is_task_ctx())
|
||||
self.r#async.unwrap_or(tokio::is_task_ctx())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,23 +374,19 @@ impl io::Write for Mock {
|
||||
// use tokio::*;
|
||||
|
||||
mod tokio {
|
||||
extern crate futures;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_timer;
|
||||
|
||||
use super::*;
|
||||
|
||||
use self::futures::{Future, Stream, Poll, Async};
|
||||
use self::futures::sync::mpsc;
|
||||
use self::futures::task::{self, Task};
|
||||
use self::tokio_io::{AsyncRead, AsyncWrite};
|
||||
use self::tokio_timer::{Timer, Sleep};
|
||||
use futures::{Future, Stream, Poll, Async};
|
||||
use futures::sync::mpsc;
|
||||
use futures::task::{self, Task};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_timer::{Timer, Sleep};
|
||||
|
||||
use std::io;
|
||||
|
||||
impl Builder {
|
||||
pub fn set_async(&mut self, is_async: bool) -> &mut Self {
|
||||
self.async = Some(is_async);
|
||||
self.r#async = Some(is_async);
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -467,7 +461,7 @@ mod tokio {
|
||||
pub fn async_read(me: &mut Mock, dst: &mut [u8]) -> io::Result<usize> {
|
||||
loop {
|
||||
if let Some(ref mut sleep) = me.tokio.sleep {
|
||||
let res = try!(sleep.poll());
|
||||
let res = r#try!(sleep.poll());
|
||||
|
||||
if !res.is_ready() {
|
||||
return Err(io::ErrorKind::WouldBlock.into());
|
||||
@@ -509,7 +503,7 @@ mod tokio {
|
||||
pub fn async_write(me: &mut Mock, src: &[u8]) -> io::Result<usize> {
|
||||
loop {
|
||||
if let Some(ref mut sleep) = me.tokio.sleep {
|
||||
let res = try!(sleep.poll());
|
||||
let res = r#try!(sleep.poll());
|
||||
|
||||
if !res.is_ready() {
|
||||
return Err(io::ErrorKind::WouldBlock.into());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
// Re-export H2 crate
|
||||
pub use super::h2;
|
||||
pub use h2;
|
||||
|
||||
pub use self::h2::*;
|
||||
pub use self::h2::client;
|
||||
pub use self::h2::frame::StreamId;
|
||||
pub use self::h2::server;
|
||||
pub use h2::*;
|
||||
pub use h2::client;
|
||||
pub use h2::frame::StreamId;
|
||||
pub use h2::server;
|
||||
|
||||
// Re-export mock
|
||||
pub use super::mock::{self, HandleFutureExt};
|
||||
@@ -22,11 +22,16 @@ pub use super::util;
|
||||
// Re-export some type defines
|
||||
pub use super::{Codec, SendFrame};
|
||||
|
||||
// Re-export macros
|
||||
pub use super::{assert_ping, assert_data, assert_headers, assert_closed,
|
||||
raw_codec, poll_frame, poll_err};
|
||||
|
||||
// Re-export useful crates
|
||||
pub use super::{bytes, env_logger, futures, http, mock_io, tokio_io};
|
||||
pub use {bytes, env_logger, futures, http, tokio_io};
|
||||
pub use super::mock_io;
|
||||
|
||||
// Re-export primary future types
|
||||
pub use self::futures::{Future, IntoFuture, Sink, Stream};
|
||||
pub use futures::{Future, IntoFuture, Sink, Stream};
|
||||
|
||||
// And our Future extensions
|
||||
pub use super::future_ext::{FutureExt, Unwrap};
|
||||
@@ -35,9 +40,9 @@ pub use super::future_ext::{FutureExt, Unwrap};
|
||||
pub use super::client_ext::{SendRequestExt};
|
||||
|
||||
// Re-export HTTP types
|
||||
pub use self::http::{uri, HeaderMap, Method, Request, Response, StatusCode, Version};
|
||||
pub use http::{uri, HeaderMap, Method, Request, Response, StatusCode, Version};
|
||||
|
||||
pub use self::bytes::{Buf, BufMut, Bytes, BytesMut, IntoBuf};
|
||||
pub use bytes::{Buf, BufMut, Bytes, BytesMut, IntoBuf};
|
||||
|
||||
pub use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
@@ -53,7 +58,7 @@ pub trait MockH2 {
|
||||
fn handshake(&mut self) -> &mut Self;
|
||||
}
|
||||
|
||||
impl MockH2 for mock_io::Builder {
|
||||
impl MockH2 for super::mock_io::Builder {
|
||||
fn handshake(&mut self) -> &mut Self {
|
||||
self.write(b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
|
||||
// Settings frame
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use h2;
|
||||
|
||||
use super::string::{String, TryFrom};
|
||||
use string::{String, TryFrom};
|
||||
use bytes::Bytes;
|
||||
use futures::{Async, Future, Poll};
|
||||
|
||||
@@ -44,7 +44,7 @@ impl Future for WaitForCapacity {
|
||||
type Error = ();
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, ()> {
|
||||
let _ = try_ready!(self.stream().poll_capacity().map_err(|_| panic!()));
|
||||
let _ = futures::try_ready!(self.stream().poll_capacity().map_err(|_| panic!()));
|
||||
|
||||
let act = self.stream().capacity();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user