buf: Inital pass at updating BufStream (#1355)

This commit is contained in:
Lucio Franco 2019-07-25 14:21:48 -04:00 committed by GitHub
parent 298be80249
commit f311ac3d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 26 additions and 17 deletions

View File

@ -2,7 +2,7 @@
members = [
"tokio",
# "tokio-buf",
"tokio-buf",
"tokio-codec",
"tokio-current-thread",
"tokio-executor",

View File

@ -24,11 +24,10 @@ publish = false
[dependencies]
bytes = "0.4.10"
either = { version = "1.5", optional = true}
futures = "0.1.23"
[features]
default = ["util"]
util = ["bytes/either", "either"]
# default = ["util"]
# util = ["bytes/either", "either"]
[dev-dependencies]
tokio-mock-task = "0.1.1"

View File

@ -15,20 +15,20 @@
//! instead of yielding arbitrary values, it only yields types that implement
//! `Buf` (i.e, byte collections).
mod never;
// mod never;
mod size_hint;
mod str;
mod u8;
#[cfg(feature = "util")]
pub mod util;
// mod str;
// mod u8;
// #[cfg(feature = "util")]
// pub mod util;
pub use self::size_hint::SizeHint;
#[doc(inline)]
#[cfg(feature = "util")]
pub use crate::util::BufStreamExt;
// #[doc(inline)]
// #[cfg(feature = "util")]
// pub use crate::util::BufStreamExt;
use bytes::Buf;
use futures::Poll;
use std::task::{Context, Poll};
/// An asynchronous stream of bytes.
///
@ -68,7 +68,7 @@ pub trait BufStream {
///
/// Once a stream is finished, i.e. `Ready(None)` has been returned, further
/// calls to `poll_buf` may result in a panic or other "bad behavior".
fn poll_buf(&mut self) -> Poll<Option<Self::Item>, Self::Error>;
fn poll_buf(&mut self, cx: &mut Context<'_>) -> Poll<Option<Result<Self::Item, Self::Error>>>;
/// Returns the bounds on the remaining length of the stream.
///

View File

@ -1,5 +1,8 @@
use tokio_buf::BufStream;
// Ensures that `BufStream` can be a trait object
#[allow(dead_code)]
fn obj(_: &mut dyn BufStream<Item = u32, Error = ()>) {}
#[test]
fn object_safe() {
// Ensures that `BufStream` can be a trait object
#[allow(dead_code)]
fn obj(_: &mut dyn BufStream<Item = u32, Error = ()>) {}
}

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
#![cfg(feature = "util")]
use futures::Async::*;

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
#![cfg(feature = "util")]
use bytes::Bytes;

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
use futures::Async::*;
use std::io::Cursor;
use tokio_buf::{util, BufStream};

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
#![cfg(feature = "util")]
use futures::Async::*;

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
use futures::sync::mpsc;
use futures::Async::*;
use std::io::Cursor;

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
use futures::Async::*;
use std::fmt;
use tokio_buf::BufStream;

View File

@ -1,3 +1,4 @@
#![cfg(feature = "broken")]
#![allow(unused)]
use bytes::Buf;