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§
source§impl<'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§
source§impl<'a> Clone for UntypedResponse<'a>
impl<'a> Clone for UntypedResponse<'a>
source§fn clone(&self) -> UntypedResponse<'a>
fn clone(&self) -> UntypedResponse<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a> Debug for UntypedResponse<'a>
impl<'a> Debug for UntypedResponse<'a>
source§impl<'de, 'a> Deserialize<'de> for UntypedResponse<'a>
impl<'de, 'a> Deserialize<'de> for UntypedResponse<'a>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<'a> Hash for UntypedResponse<'a>
impl<'a> Hash for UntypedResponse<'a>
source§impl<'a> PartialEq<UntypedResponse<'a>> for UntypedResponse<'a>
impl<'a> PartialEq<UntypedResponse<'a>> for UntypedResponse<'a>
source§fn eq(&self, other: &UntypedResponse<'a>) -> bool
fn eq(&self, other: &UntypedResponse<'a>) -> bool
self and other values to be equal, and is used
by ==.