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
impl Response
Sourcepub fn new() -> Self
pub fn new() -> Self
Start building a new Response. Attempting to send this Response will not succeed
until its body has been set with [Response::body() or Response::try_body().
Sourcepub fn inherit(self, inherit: bool) -> Self
pub fn inherit(self, inherit: bool) -> Self
Set whether this Response will “inherit” the blob of the crate::Request
that this process most recently received. Unlike with crate::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.
Sourcepub fn body<T>(self, body: T) -> Self
pub fn body<T>(self, body: T) -> Self
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 Response::try_body() instead of this.
Sourcepub fn metadata(self, metadata: &str) -> Self
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.
Sourcepub fn blob(self, blob: LazyLoadBlob) -> Self
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.
Sourcepub fn blob_mime(self, mime: &str) -> Self
pub fn blob_mime(self, mime: &str) -> Self
Set the LazyLoadBlobs 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.
Sourcepub fn blob_bytes<T>(self, bytes: T) -> Self
pub fn blob_bytes<T>(self, bytes: T) -> Self
Set the LazyLoadBlobs 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.
Sourcepub fn try_blob_bytes<T, E>(self, bytes: T) -> Result<Self, E>
pub fn try_blob_bytes<T, E>(self, bytes: T) -> Result<Self, E>
Set the LazyLoadBlobs bytes with a type that implements TryInto<Vec<u8>>
and may or may not successfully be set.
Sourcepub fn capabilities(self, capabilities: Vec<Capability>) -> Self
pub fn capabilities(self, capabilities: Vec<Capability>) -> Self
Attach capabilities to this next Response.
Sourcepub fn attach_all(self, target: &Address) -> Self
pub fn attach_all(self, target: &Address) -> Self
Attach all capabilities we have that were issued by target to the next message.
Sourcepub fn send(self) -> Result<(), BuildError>
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§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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