kinode_process_lib

Struct Response

source
pub struct Response { /* private fields */ }
Expand description

Response builder. Use Response::new() to start a response, then build it, then call Response::send() on it to fire.

Implementations§

source§

impl Response

source

pub fn new() -> Self

Start building a new response. Attempting to send this response will not succeed until its body has been set with body() or try_body().

source

pub fn inherit(self, inherit: bool) -> Self

Set whether this response will “inherit” the blob of the request that this process most recently received. Unlike with requests, the inherit field of a response only deals with blob attachment, since responses don’t themselves have to consider responses or contexts.

Note that if the blob is set for this response, this flag will not override it.

source

pub fn body<T>(self, body: T) -> Self
where T: Into<Vec<u8>>,

Set the IPC body (Inter-Process Communication) value for this message. This field is mandatory. An IPC body is simply a vector of bytes. Process developers are responsible for architecting the serialization/derserialization strategy for these bytes, but the simplest and most common strategy is just to use a JSON spec that gets stored in bytes as a UTF-8 string.

If the serialization strategy is complex, it’s best to define it as an impl of TryInto on your IPC body type, then use try_body() instead of this.

source

pub fn try_body<T, E>(self, body: T) -> Result<Self, E>
where T: TryInto<Vec<u8>, Error = E>, E: Error,

Set the IPC body (Inter-Process Communication) value for this message, using a type that’s got an implementation of TryInto for Vec<u8>. It’s best to define an IPC body type within your app, then implement TryFrom/TryInto for all IPC body serialization/deserialization.

source

pub fn metadata(self, metadata: &str) -> Self

Set the metadata field for this response. Metadata is simply a String. Metadata should usually be used for middleware and other message-passing situations that require the original IPC body and blob to be preserved. As such, metadata should not always be expected to reach the final destination of this response unless the full chain of behavior is known / controlled by the developer.

source

pub fn blob(self, blob: LazyLoadBlob) -> Self

Set the blob of this response. A LazyLoadBlob holds bytes and an optional MIME type.

The purpose of having a blob field distinct from the IPC body field is to enable performance optimizations in all sorts of situations. LazyLoadBlobs are only brought across the runtime<>Wasm boundary if the process calls get_blob(), and this saves lots of work in data-intensive pipelines.

LazyLoadBlobs also provide a place for less-structured data, such that an IPC body type can be quickly locked in and upgraded within an app-protocol without breaking changes, while still allowing freedom to adjust the contents and shape of a blob. IPC body formats should be rigorously defined.

source

pub fn blob_mime(self, mime: &str) -> Self

Set the blob’s MIME type. If a blob has not been set, it will be set here as an empty vector of bytes. If it has been set, the MIME type will be replaced or created.

source

pub fn blob_bytes<T>(self, bytes: T) -> Self
where T: Into<Vec<u8>>,

Set the blob’s bytes. If a blob has not been set, it will be set here with no MIME type. If it has been set, the bytes will be replaced with these bytes.

source

pub fn try_blob_bytes<T, E>(self, bytes: T) -> Result<Self, E>
where T: TryInto<Vec<u8>, Error = E>, E: Error,

Set the blob’s bytes with a type that implements TryInto<Vec<u8>> and may or may not successfully be set.

source

pub fn capabilities(self, capabilities: Vec<Capability>) -> Self

Add capabilities to this response. Capabilities are a way to pass

source

pub fn send(self) -> Result<(), BuildError>

Attempt to send the response. This will only fail if the IPC body field of the response has not yet been set using body() or try_body().

Trait Implementations§

source§

impl Default for Response

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more