Struct distant_net::common::UntypedResponse
source · pub struct UntypedResponse<'a> {
pub id: Cow<'a, str>,
pub origin_id: Cow<'a, str>,
pub payload: Cow<'a, [u8]>,
}Expand description
Represents a response to send whose payload is bytes instead of a specific type
Fields
id: Cow<'a, str>Unique id associated with the response
origin_id: Cow<'a, str>Unique id associated with the response that triggered the response
payload: Cow<'a, [u8]>Payload associated with the response as bytes
Implementations
sourceimpl<'a> UntypedResponse<'a>
impl<'a> UntypedResponse<'a>
sourcepub fn to_typed_response<T: DeserializeOwned>(&self) -> Result<Response<T>>
pub fn to_typed_response<T: DeserializeOwned>(&self) -> Result<Response<T>>
Attempts to convert an untyped request to a typed request
sourcepub fn as_borrowed(&self) -> UntypedResponse<'_>
pub fn as_borrowed(&self) -> UntypedResponse<'_>
Convert into a borrowed version
sourcepub fn into_owned(self) -> UntypedResponse<'static>
pub fn into_owned(self) -> UntypedResponse<'static>
Convert into an owned version
sourcepub fn set_id(&mut self, id: impl Into<String>)
pub fn set_id(&mut self, id: impl Into<String>)
Updates the id of the response to the given id.
sourcepub fn set_origin_id(&mut self, origin_id: impl Into<String>)
pub fn set_origin_id(&mut self, origin_id: impl Into<String>)
Updates the origin id of the response to the given origin_id.
sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Allocates a new collection of bytes representing the response.
sourcepub fn from_slice(input: &'a [u8]) -> Result<Self, UntypedResponseParseError>
pub fn from_slice(input: &'a [u8]) -> Result<Self, UntypedResponseParseError>
Parses a collection of bytes, returning an untyped response if it can be potentially
represented as a Response depending on the payload, or the original bytes if it does not
represent a Response.
NOTE: This supports parsing an invalid response where the payload would not properly deserialize, but the bytes themselves represent a complete response of some kind.
Trait Implementations
sourceimpl<'a> Clone for UntypedResponse<'a>
impl<'a> Clone for UntypedResponse<'a>
sourcefn clone(&self) -> UntypedResponse<'a>
fn clone(&self) -> UntypedResponse<'a>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more