1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01: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 router::{Router, Pattern};
pub use pipeline::Pipeline;
pub use payload::{PayloadSender, PayloadWriter};
pub use channel::{HttpChannel, HttpHandler, IntoHttpHandler};
pub use param::{FromParam, Params};
pub use server::ServerSettings;

View File

@ -45,6 +45,7 @@ impl fmt::Debug for PayloadItem {
/// Stream of byte chunks
///
/// Payload stores chunks in vector. First chunk can be received with `.readany()` method.
/// Payload stream is not thread safe.
#[derive(Debug)]
pub struct Payload {
inner: Rc<RefCell<Inner>>,
@ -52,7 +53,14 @@ pub struct 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)));
(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);
/// Write eof into a stream which closes reading side of a stream.
fn feed_eof(&mut self);
/// Feed bytes into a payload stream
fn feed_data(&mut self, data: Bytes);
/// Get estimated available capacity
fn capacity(&self) -> usize;
}
pub(crate) struct PayloadSender {
/// Sender part of the payload stream
pub struct PayloadSender {
inner: Weak<RefCell<Inner>>,
}