1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-05 09:42:08 +00:00

make payload sender public

This commit is contained in:
Nikolay Kim 2017-12-18 21:58:38 -08:00
parent 64dc6c5771
commit 0cab873066
2 changed files with 18 additions and 3 deletions

View file

@ -167,6 +167,7 @@ pub mod dev {
pub use handler::Handler; pub use handler::Handler;
pub use router::{Router, Pattern}; pub use router::{Router, Pattern};
pub use pipeline::Pipeline; pub use pipeline::Pipeline;
pub use payload::{PayloadSender, PayloadWriter};
pub use channel::{HttpChannel, HttpHandler, IntoHttpHandler}; pub use channel::{HttpChannel, HttpHandler, IntoHttpHandler};
pub use param::{FromParam, Params}; pub use param::{FromParam, Params};
pub use server::ServerSettings; pub use server::ServerSettings;

View file

@ -45,6 +45,7 @@ impl fmt::Debug for PayloadItem {
/// Stream of byte chunks /// Stream of byte chunks
/// ///
/// Payload stores chunks in vector. First chunk can be received with `.readany()` method. /// Payload stores chunks in vector. First chunk can be received with `.readany()` method.
/// Payload stream is not thread safe.
#[derive(Debug)] #[derive(Debug)]
pub struct Payload { pub struct Payload {
inner: Rc<RefCell<Inner>>, inner: Rc<RefCell<Inner>>,
@ -52,7 +53,14 @@ pub struct Payload {
impl Payload { impl Payload {
pub(crate) fn new(eof: bool) -> (PayloadSender, Payload) { /// Create payload stream.
///
/// This method construct two objects responsible for bytes stream generation.
///
/// * `PayloadSender` - *Sender* side of the stream
///
/// * `Payload` - *Receiver* side of the stream
pub fn new(eof: bool) -> (PayloadSender, Payload) {
let shared = Rc::new(RefCell::new(Inner::new(eof))); let shared = Rc::new(RefCell::new(Inner::new(eof)));
(PayloadSender{inner: Rc::downgrade(&shared)}, Payload{inner: shared}) (PayloadSender{inner: Rc::downgrade(&shared)}, Payload{inner: shared})
@ -138,17 +146,23 @@ impl Stream for Payload {
} }
} }
pub(crate) trait PayloadWriter { pub trait PayloadWriter {
/// Set stream error.
fn set_error(&mut self, err: PayloadError); fn set_error(&mut self, err: PayloadError);
/// Write eof into a stream which closes reading side of a stream.
fn feed_eof(&mut self); fn feed_eof(&mut self);
/// Feed bytes into a payload stream
fn feed_data(&mut self, data: Bytes); fn feed_data(&mut self, data: Bytes);
/// Get estimated available capacity
fn capacity(&self) -> usize; fn capacity(&self) -> usize;
} }
pub(crate) struct PayloadSender { /// Sender part of the payload stream
pub struct PayloadSender {
inner: Weak<RefCell<Inner>>, inner: Weak<RefCell<Inner>>,
} }