Struct Body
pub struct Body { /* private fields */ }
The body of a Request.
In most cases, this is not needed directly, as the
RequestBuilder.body method uses Into<Body>, which allows
passing many things (like a string or vector of bytes).
Implementations
impl Body
fn new<R: Read + Send + 'static>(reader: R) -> BodyInstantiate a
Bodyfrom a reader.Note
While allowing for many types to be used, these bodies do not have a way to reset to the beginning and be reused. This means that when encountering a 307 or 308 status code, instead of repeating the request at the new location, the
Responsewill be returned with the redirect status code set.# use File; # use Body; #If you have a set of bytes, like
StringorVec<u8>, using theFromimplementations forBodywill store the data in a manner it can be reused.# use Body; #fn sized<R: Read + Send + 'static>(reader: R, len: u64) -> BodyCreate a
Bodyfrom aReadwhere the size is known in advance but the data should not be fully loaded into memory. This will set theContent-Lengthheader and stream from theRead.# use File; # use Body; #fn as_bytes(&self) -> Option<&[u8]>Returns the body as a byte slice if the body is already buffered in memory. For streamed requests this method returns
None.fn buffer(&mut self) -> Result<&[u8], Error>Converts streamed requests to their buffered equivalent and returns a reference to the buffer. If the request is already buffered, this has no effect.
Be aware that for large requests this method is expensive and may cause your program to run out of memory.
Trait Implementations
impl Debug for Body
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl From<&'static [u8]> for Body
fn from(s: &'static [u8]) -> Body
impl From<&'static str> for Body
fn from(s: &'static str) -> Body
impl From<Bytes> for Body
fn from(b: Bytes) -> Body
impl From<File> for Body
fn from(f: File) -> Body
impl From<String> for Body
fn from(s: String) -> Body
impl From<Vec<u8>> for Body
fn from(v: Vec<u8>) -> Body
Auto Trait Implementations
impl !Freeze for Body
impl !RefUnwindSafe for Body
impl !Sync for Body
impl !UnwindSafe for Body
impl Send for Body
impl Unpin for Body
impl UnsafeUnpin for Body
Blanket Implementations
impl<T> Any for Body
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Body
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Body
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Body
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for Body
impl<T> PolicyExt for Body
where
T: ?Sized,
fn and<P, B, E>(self, other: P) -> And<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,fn or<P, B, E>(self, other: P) -> Or<T, P> where T: Sized + Policy<B, E>, P: Policy<B, E>,
impl<T> WithSubscriber for Body
impl<T, U> Into<U> for Body
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Body
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Body
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>