Implement 'From<T>' for 'Stream<T>' instead of custom 'from'.

Closes #267.
This commit is contained in:
Joshua Rombauer 2017-04-18 23:10:18 +02:00 committed by Sergio Benitez
parent d6e86be1b0
commit 0e759edf78

View File

@ -13,24 +13,6 @@ use http::Status;
pub struct Stream<T: Read>(T, u64);
impl<T: Read> Stream<T> {
/// Create a new stream from the given `reader`.
///
/// # Example
///
/// Stream a response from whatever is in `stdin`. Note: you probably
/// shouldn't do this.
///
/// ```rust
/// use std::io;
/// use rocket::response::Stream;
///
/// # #[allow(unused_variables)]
/// let response = Stream::from(io::stdin());
/// ```
pub fn from(reader: T) -> Stream<T> {
Stream(reader, DEFAULT_CHUNK_SIZE)
}
/// Create a new stream from the given `reader` and sets the chunk size for
/// each streamed chunk to `chunk_size` bytes.
///
@ -57,6 +39,26 @@ impl<T: Read + Debug> Debug for Stream<T> {
}
}
/// Create a new stream from the given `reader`.
///
/// # Example
///
/// Stream a response from whatever is in `stdin`. Note: you probably
/// shouldn't do this.
///
/// ```rust
/// use std::io;
/// use rocket::response::Stream;
///
/// # #[allow(unused_variables)]
/// let response = Stream::from(io::stdin());
/// ```
impl<T: Read> From<T> for Stream<T> {
fn from(reader: T) -> Self {
Stream(reader, DEFAULT_CHUNK_SIZE)
}
}
/// Sends a response to the client using the "Chunked" transfer encoding. The
/// maximum chunk size is 4KiB.
///