Enum servlin::RequestBody
source · pub enum RequestBody {
PendingKnown(u64),
PendingUnknown,
StaticBytes(&'static [u8]),
StaticStr(&'static str),
Vec(Vec<u8>),
File(PathBuf, u64),
TempFile(TempFile, u64),
}
Variants§
PendingKnown(u64)
PendingUnknown
StaticBytes(&'static [u8])
StaticStr(&'static str)
Vec(Vec<u8>)
File(PathBuf, u64)
TempFile(TempFile, u64)
Implementations§
source§impl RequestBody
impl RequestBody
pub fn empty() -> Self
sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Examples found in repository?
examples/http-put.rs (line 54)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
fn put(state: Arc<State>, req: Request) -> Result<Response, Error> {
if req.body.is_pending() {
return Ok(Response::get_body_and_reprocess(1024 * 1024));
}
let body_len = req.body.reader()?.bytes().count();
state.upload_count.fetch_add(1, Ordering::AcqRel);
Ok(Response::text(
200,
format!(
"Upload received, body_len={}, upload_count={}\n",
body_len,
state.upload_count.load(Ordering::Acquire)
),
))
}
pub fn is_empty(&self) -> Option<bool>
sourcepub fn reader(&self) -> Result<BodyReader<'_>, Error>
pub fn reader(&self) -> Result<BodyReader<'_>, Error>
Errors
Returns an error when the body is cached in a file and we fail to open the file.
Examples found in repository?
examples/http-put.rs (line 57)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
fn put(state: Arc<State>, req: Request) -> Result<Response, Error> {
if req.body.is_pending() {
return Ok(Response::get_body_and_reprocess(1024 * 1024));
}
let body_len = req.body.reader()?.bytes().count();
state.upload_count.fetch_add(1, Ordering::AcqRel);
Ok(Response::text(
200,
format!(
"Upload received, body_len={}, upload_count={}\n",
body_len,
state.upload_count.load(Ordering::Acquire)
),
))
}
sourcepub async fn async_reader(&self) -> Result<BodyAsyncReader<'_>, Error>
pub async fn async_reader(&self) -> Result<BodyAsyncReader<'_>, Error>
Errors
Returns an error when the body is cached in a file and we fail to open the file.
Trait Implementations§
source§impl Clone for RequestBody
impl Clone for RequestBody
source§fn clone(&self) -> RequestBody
fn clone(&self) -> RequestBody
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for RequestBody
impl Debug for RequestBody
source§impl From<&'static [u8]> for RequestBody
impl From<&'static [u8]> for RequestBody
source§impl From<&'static str> for RequestBody
impl From<&'static str> for RequestBody
source§impl From<String> for RequestBody
impl From<String> for RequestBody
source§impl PartialEq for RequestBody
impl PartialEq for RequestBody
source§fn eq(&self, other: &RequestBody) -> bool
fn eq(&self, other: &RequestBody) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl TryFrom<RequestBody> for String
impl TryFrom<RequestBody> for String
impl Eq for RequestBody
impl StructuralEq for RequestBody
impl StructuralPartialEq for RequestBody
Auto Trait Implementations§
impl RefUnwindSafe for RequestBody
impl Send for RequestBody
impl Sync for RequestBody
impl Unpin for RequestBody
impl UnwindSafe for RequestBody
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