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 body() or 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 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.
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 try_body() instead of this.
sourcepub fn try_body<T, E>(self, body: T) -> Result<Self, E>
pub fn try_body<T, E>(self, body: T) -> Result<Self, E>
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.
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 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.
sourcepub fn blob_bytes<T>(self, bytes: T) -> Self
pub fn blob_bytes<T>(self, bytes: T) -> Self
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.
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 blob’s 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
Add capabilities to this response. Capabilities are a way to pass
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