Skip to main content

WriteContext

Struct WriteContext 

Source
pub struct WriteContext<'a>(/* private fields */);
Expand description

Request, response and read-write KV access for one call of a Registry::read_write handler.

Borrowed request data must be copied before calling a &mut self method, and cannot outlive the context:

ⓘ
use ccf_app::{EndpointResult, WriteContext};

fn echo(context: &mut WriteContext<'_>) -> EndpointResult {
    let body = context.body()?;
    context.set_body(body)?;
    Ok(())
}
ⓘ
use ccf_app::WriteContext;

fn retain_body(context: &WriteContext<'_>) -> &'static [u8] {
    context.body().unwrap()
}

Implementations§

Source§

impl<'ctx> WriteContext<'ctx>

Source

pub fn body(&self) -> BridgeResult<&[u8]>

Borrow the raw request body. Copy it before calling a &mut self method if it is still needed.

Source

pub fn query(&self) -> BridgeResult<&str>

Borrow the raw query string, without the leading ? and not percent-decoded.

Source

pub fn path_param(&mut self, name: &str) -> BridgeResult<Option<String>>

Copy the decoded path parameter name, such as "key" for /records/{key}, or None if it is absent.

Source

pub fn header(&mut self, name: &str) -> BridgeResult<Option<Vec<u8>>>

Copy the raw value of the request header name, which must be lowercase, or None if it is absent.

Source

pub fn set_status(&mut self, status: u16) -> BridgeResult<()>

Set the response status. Unknown statuses are rejected with BridgeError::InvalidArgument.

Source

pub fn set_header(&mut self, name: &str, value: &str) -> BridgeResult<()>

Set a response header. Invalid names and values, including any containing CR or LF, are rejected with BridgeError::InvalidArgument.

Source

pub fn set_body(&mut self, body: &[u8]) -> BridgeResult<()>

Set the raw response body.

Source

pub fn map<'a>(&'a mut self, name: &'a str) -> Map<'a, 'ctx>

Access the map name in this call’s transaction.

Auto Trait Implementations§

§

impl<'a> Freeze for WriteContext<'a>

§

impl<'a> RefUnwindSafe for WriteContext<'a>

§

impl<'a> !Send for WriteContext<'a>

§

impl<'a> !Sync for WriteContext<'a>

§

impl<'a> Unpin for WriteContext<'a>

§

impl<'a> UnsafeUnpin for WriteContext<'a>

§

impl<'a> !UnwindSafe for WriteContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.