#[repr(transparent)]
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

An invalid body handle.

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

Returns true if the body handle is valid.

Returns true if the body handle is invalid.

Make a handle from its underlying representation.

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Get the underlying representation of the handle.

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Get a mutable reference to the underlying u32 representation of the handle.

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

Turn a handle into its representation without closing the underlying resource.

This should only be used when calling the raw ABI directly, and care should be taken not to reuse or alias handle values.

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().

Acquire a new, empty body handle.

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.

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.

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.

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]);

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

Examples
body.write_str("woof woof");

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_str("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

Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read, except that it reads into a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
Creates a “by reference” adaptor for this instance of Read. Read more
Transforms this Read instance to an Iterator over its bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.