[][src]Struct fastly::handle::BodyHandle

#[repr(transparent)]pub struct BodyHandle { /* fields omitted */ }

A low-level interface to HTTP bodies.

For most applications, you should use Body instead of this interface. See the top-level handle documentation for more details.

This type implements Read to read bytes from the beginning of a body, and Write to write to the end of a body. Note that these operations are unbuffered, unlike the same operations on the higher-level Body type.

Implementations

impl BodyHandle[src]

pub const INVALID: Self[src]

An invalid body handle.

This is primarily useful to represent uninitialized values when using the interfaces in fastly_sys.

pub fn is_valid(&self) -> bool[src]

Returns true if the body handle is valid.

pub fn is_invalid(&self) -> bool[src]

Returns true if the body handle is invalid.

pub fn from_client() -> Self[src]

Get a handle to the client request body.

This handle may only be retrieved once per execution, either through this function or through client_request_and_body().

pub fn new() -> Self[src]

Acquire a new, empty body handle.

pub fn append(&mut self, other: BodyHandle)[src]

Append another body onto the end of this body.

This operation is performed in amortized constant time, and so should always be preferred to reading an entire body and then writing the same contents to another body.

The other body will no longer be valid after this call.

pub fn into_bytes(self) -> Vec<u8>

Notable traits for Vec<u8, Global>

impl Write for Vec<u8, Global>
[src]

Read the entirety of the body into a byte vector.

Memory usage

This method will cause the entire body to be buffered in WebAssembly memory. You should take care not to exceed the WebAssembly memory limits, and consider using Read methods to control how much of the body you process at once.

pub fn into_string(self) -> String[src]

Read the entirety of the body into a String, interpreting the bytes as UTF-8.

Memory usage

This method will cause the entire body to be buffered in WebAssembly memory. You should take care not to exceed the WebAssembly memory limits, and consider using Read methods to control how much of the body you process at once.

Panics

If the body does not contain a valid UTF-8 string, this function will panic. To explicitly handle the possibility of invalid UTF-8 data, use into_bytes() and then convert the bytes explicitly with a function like String::from_utf8.

pub fn write_bytes(&mut self, bytes: &[u8]) -> usize[src]

Write a slice of bytes to the end of this body, and return the number of bytes written.

Examples

body.write_bytes(&[0, 1, 2, 3]);

pub fn write_str(&mut self, string: &str) -> usize[src]

Write a string slice to the end of this body, and return the number of bytes written.

Examples

body.write_str("woof woof");

Trait Implementations

impl Debug for BodyHandle[src]

impl Eq for BodyHandle[src]

impl From<&'_ [u8]> for BodyHandle[src]

impl From<&'_ str> for BodyHandle[src]

impl From<BodyHandle> for Body[src]

impl From<String> for BodyHandle[src]

impl From<Vec<u8, Global>> for BodyHandle[src]

impl Hash for BodyHandle[src]

impl PartialEq<BodyHandle> for BodyHandle[src]

impl Read for BodyHandle[src]

impl StructuralEq for BodyHandle[src]

impl StructuralPartialEq for BodyHandle[src]

impl Write for BodyHandle[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.