pub struct BodyHandle { /* private fields */ }Expand description
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§
Source§impl BodyHandle
impl BodyHandle
Sourcepub const INVALID: Self
pub const INVALID: Self
An invalid body handle.
This is primarily useful to represent uninitialized values when using the interfaces in
fastly_sys.
Sourcepub const fn is_invalid(&self) -> bool
pub const fn is_invalid(&self) -> bool
Returns true if the body handle is invalid.
Sourcepub unsafe fn from_u32(handle: u32) -> Self
pub unsafe fn from_u32(handle: u32) -> Self
Make a handle from its underlying representation.
§Safety
This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.
Sourcepub unsafe fn as_u32(&self) -> u32
pub unsafe fn as_u32(&self) -> u32
Get the underlying representation of the handle.
§Safety
This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.
Sourcepub unsafe fn as_u32_mut(&mut self) -> &mut u32
pub unsafe fn as_u32_mut(&mut self) -> &mut u32
Get a mutable reference to the underlying u32 representation of the handle.
§Safety
This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.
Sourcepub fn into_u32(self) -> u32
pub fn into_u32(self) -> u32
Turn a handle into its representation without closing the underlying resource.
§Safety
This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.
Sourcepub fn from_client() -> Self
pub fn from_client() -> Self
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().
Sourcepub fn append(&mut self, other: BodyHandle)
pub fn append(&mut self, other: BodyHandle)
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.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
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.
Sourcepub fn close(self) -> Result<(), HandleError>
pub fn close(self) -> Result<(), HandleError>
Close the BodyHandle by removing it from the host Session. This will close out streaming and non streaming bodies. Care must be taken to only close out the handle if the body is not being written to or read from anymore. If the handle has already been closed an error will be returned.
§Examples
let mut body = BodyHandle::new();
body.write_all(b"You're already closed.")?;
// The handle is not being used in a request and doesn't refer to any
// response body so we can close this out
body.close()?;Trait Implementations§
Source§impl BodyHandleExt for BodyHandle
impl BodyHandleExt for BodyHandle
Source§fn get_trailer_names<'a>(
&'a self,
buf_size: usize,
) -> Result<Box<dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a>, BodyHandleError>
fn get_trailer_names<'a>( &'a self, buf_size: usize, ) -> Result<Box<dyn Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a>, BodyHandleError>
Source§fn get_trailer_value(
&self,
name: &HeaderName,
max_len: usize,
) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>
fn get_trailer_value( &self, name: &HeaderName, max_len: usize, ) -> Result<Result<Option<HeaderValue>, BufferSizeError>, BodyHandleError>
Source§fn get_trailer_values<'a>(
&'a self,
name: &'a HeaderName,
max_len: usize,
) -> Result<Box<dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a>, BodyHandleError>
fn get_trailer_values<'a>( &'a self, name: &'a HeaderName, max_len: usize, ) -> Result<Box<dyn Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a>, BodyHandleError>
Source§impl Debug for BodyHandle
impl Debug for BodyHandle
Source§impl Drop for BodyHandle
impl Drop for BodyHandle
Source§impl From<&[u8]> for BodyHandle
impl From<&[u8]> for BodyHandle
Source§impl From<&str> for BodyHandle
impl From<&str> for BodyHandle
Source§impl From<BodyHandle> for Body
impl From<BodyHandle> for Body
Source§fn from(handle: BodyHandle) -> Self
fn from(handle: BodyHandle) -> Self
Source§impl From<String> for BodyHandle
impl From<String> for BodyHandle
Source§impl Hash for BodyHandle
impl Hash for BodyHandle
Source§impl PartialEq for BodyHandle
impl PartialEq for BodyHandle
Source§impl Read for BodyHandle
impl Read for BodyHandle
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl Write for BodyHandle
impl Write for BodyHandle
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)impl Eq for BodyHandle
impl StructuralPartialEq for BodyHandle
Auto Trait Implementations§
impl Freeze for BodyHandle
impl RefUnwindSafe for BodyHandle
impl Send for BodyHandle
impl Sync for BodyHandle
impl Unpin for BodyHandle
impl UnsafeUnpin for BodyHandle
impl UnwindSafe for BodyHandle
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more