pub struct Payload(pub Payload);Expand description
Payload extractor returns request’s payload stream.
§Example
use std::future::Future;
use ntex::util::{BytesMut, Stream};
use ntex::web::{self, error, App, HttpResponse};
/// extract binary data from request
async fn index(mut body: web::types::Payload) -> Result<HttpResponse, error::PayloadError>
{
let mut bytes = BytesMut::new();
while let Some(item) = ntex::util::stream_recv(&mut body).await {
bytes.extend_from_slice(&item?);
}
format!("Body {:?}!", bytes);
Ok(HttpResponse::Ok().build())
}
fn main() {
let app = App::default().service(
web::resource("/index.html").route(
web::get().to(index))
);
}Tuple Fields§
§0: PayloadImplementations§
Trait Implementations§
Source§impl<St: State> FromRequest<St> for Payload
Get request’s payload stream
impl<St: State> FromRequest<St> for Payload
Get request’s payload stream
§Example
use std::future::Future;
use ntex::util::{BytesMut, Stream};
use ntex::web::{self, error, App, HttpResponse};
/// extract binary data from request
async fn index(mut body: web::types::Payload) -> Result<HttpResponse, error::PayloadError>
{
let mut bytes = BytesMut::new();
while let Some(item) = ntex::util::stream_recv(&mut body).await {
bytes.extend_from_slice(&item?);
}
format!("Body {:?}!", bytes);
Ok(HttpResponse::Ok().build())
}
fn main() {
let app = App::default().service(
web::resource("/index.html").route(
web::get().to(index))
);
}Source§type Error = Infallible
type Error = Infallible
The error returned when extraction fails. Read more
Source§async fn from_request(
_: &St,
_: &HttpRequest,
payload: &mut Payload,
) -> Result<Payload, Self::Error>
async fn from_request( _: &St, _: &HttpRequest, payload: &mut Payload, ) -> Result<Payload, Self::Error>
Creates the extractor value for this request.
Source§impl Stream for Payload
impl Stream for Payload
Auto Trait Implementations§
impl !RefUnwindSafe for Payload
impl !Send for Payload
impl !Sync for Payload
impl !UnwindSafe for Payload
impl Freeze for Payload
impl Unpin for Payload
impl UnsafeUnpin for Payload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more