mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-17 23:19:06 +00:00
Implement 'From<T>' for 'Stream<T>' instead of custom 'from'.
Closes #267.
This commit is contained in:
parent
d6e86be1b0
commit
0e759edf78
@ -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.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user