[−][src]Trait tower_web::util::buf_stream::BufStream
An asynchronous stream of bytes.
BufStream
asynchronously yields values implementing Buf
, i.e. byte
buffers.
Associated Types
type Item: Buf
Values yielded by the BufStream
.
type Error
The error type this BufStream
might generate.
Required methods
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
Attempt to pull out the next buffer of this stream, registering the
current task for wakeup if the value is not yet available, and returning
None
if the stream is exhausted.
Return value
There are several possible return values, each indicating a distinct stream state:
-
Ok(Async::NotReady)
means that this stream's next value is not ready yet. Implementations will ensure that the current task will be notified when the next value may be ready. -
Ok(Async::Ready(Some(buf)))
means that the stream has successfully produced a value,buf
, and may produce further values on subsequentpoll
calls. -
Ok(Async::Ready(None))
means that the stream has terminated, andpoll
should not be invoked again.
Panics
Once a stream is finished, i.e. Ready(None)
has been returned, further
calls to poll
may result in a panic or other "bad behavior".
Provided methods
fn size_hint(&self) -> SizeHint
Returns the bounds on the remaining length of the iterator.
Implementation notes
It is not enforced that a BufStreaam
yields the declared amount of
data. A buggy implementation may yield less than the lower bound or more
than the upper bound.
size_hint()
is primarily intended to be used for optimizations such as
reserving space for the data, but must not be trusted to e.g. omit
bounds checks in unsafe code. An incorrect implemeentation of
size_hint()
should not lead to memory safety violations.
That said, the implementation should provide a correct estimation, because otherwise it would be a violation of the trait's protocol.
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
Self: Sized,
T: BufStream<Error = Self::Error>,
Takes two buf streams and creates a new buf stream over both in sequence.
chain()
will return a new BufStream
value which will first yield all
data from self
then all data from other
.
In other words, it links two buf streams together, in a chain.
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
Self: Sized,
T: FromBufStream,
Consumes all data from self
, storing it in byte storage of type T
.
Implementations on Foreign Types
impl<B> BufStream for Option<B> where
B: BufStream,
[src]
B: BufStream,
type Item = B::Item
type Error = B::Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl BufStream for Bytes
[src]
type Item = Cursor<Bytes>
type Error = ()
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl<A, B> BufStream for Either<A, B> where
A: BufStream,
B: BufStream<Item = A::Item, Error = A::Error>,
[src]
A: BufStream,
B: BufStream<Item = A::Item, Error = A::Error>,
type Item = A::Item
type Error = A::Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl BufStream for File
[src]
type Item = Cursor<BytesMut>
type Error = Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl BufStream for String
[src]
type Item = Cursor<Vec<u8>>
type Error = Never
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl BufStream for &'static str
[src]
type Item = Cursor<&'static [u8]>
type Error = Never
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl BufStream for Body
[src]
type Item = Chunk
type Error = Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
Implementors
impl<Item, Error> BufStream for Empty<Item, Error> where
Item: Buf,
[src]
Item: Buf,
type Item = Item
type Error = Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl<T> BufStream for CompressStream<T> where
T: BufStream,
[src]
T: BufStream,
type Item = Cursor<Bytes>
type Error = Error<T::Error>
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl<T> BufStream for StdStream<T> where
T: Stream,
T::Item: Buf,
[src]
T: Stream,
T::Item: Buf,
type Item = T::Item
type Error = T::Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl<T, U> BufStream for Chain<T, U> where
T: BufStream,
U: BufStream<Error = T::Error>,
[src]
T: BufStream,
U: BufStream<Error = T::Error>,
type Item = Either<T::Item, U::Item>
type Error = T::Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,
impl<T: BufStream> BufStream for Map<T>
[src]
type Item = T::Item
type Error = Error
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error>
[src]
fn size_hint(&self) -> SizeHint
[src]
fn chain<T>(self, other: T) -> Chain<Self, T> where
Self: Sized,
T: BufStream<Error = Self::Error>,
[src]
Self: Sized,
T: BufStream<Error = Self::Error>,
fn collect<T>(self) -> Collect<Self, T> where
Self: Sized,
T: FromBufStream,
[src]
Self: Sized,
T: FromBufStream,