Struct unit_rs::UnitResponse
source · [−]pub struct UnitResponse<'a> { /* private fields */ }
Expand description
An object used to send follow-up response bytes to a request, obtained by
calling a UnitRequest
’s
create_response()
method. Dropping this
object will end the response.
Implementations
sourceimpl UnitResponse<'_>
impl UnitResponse<'_>
sourcepub fn send_buffer<T>(
&mut self,
size: usize,
f: impl Fn(&UnitRequest<'_>, &mut &mut [u8]) -> UnitResult<T>
) -> UnitResult<T>
pub fn send_buffer<T>(
&mut self,
size: usize,
f: impl Fn(&UnitRequest<'_>, &mut &mut [u8]) -> UnitResult<T>
) -> UnitResult<T>
Send another chunk of bytes for this request’s response. The bytes will be immediately sent to the client.
This method allocates a buffer in Unit’s shared memory region, and calls a user function to fill it.
The user function receives a &mut &mut [u8]
slice, and the write!
macro can be used to advance the start position of the slice. Only the
bytes between the original start and the new start positions will be
sent, and the rest will be discarded.
Methods from Deref<Target = UnitRequest<'a>>
sourcepub fn read_body(&self, target: &mut [u8]) -> usize
pub fn read_body(&self, target: &mut [u8]) -> usize
Copy bytes from the request body into the target buffer and return the number of bytes written.
If the buffer is smaller than the contents of the body, the contents will be truncated to the size of the buffer.
sourcepub fn fields(&self) -> impl Iterator<Item = (&str, &str)>
pub fn fields(&self) -> impl Iterator<Item = (&str, &str)>
Create an interator over all header (name, value) tuples.
sourcepub fn server_name(&self) -> &str
pub fn server_name(&self) -> &str
Return the host name of the server.
Trait Implementations
sourceimpl<'a> Deref for UnitResponse<'a>
impl<'a> Deref for UnitResponse<'a>
type Target = UnitRequest<'a>
type Target = UnitRequest<'a>
The resulting type after dereferencing.
Auto Trait Implementations
impl<'a> RefUnwindSafe for UnitResponse<'a>
impl<'a> !Send for UnitResponse<'a>
impl<'a> !Sync for UnitResponse<'a>
impl<'a> Unpin for UnitResponse<'a>
impl<'a> !UnwindSafe for UnitResponse<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more