pub struct UntypedResponse<'a> {
pub header: Cow<'a, [u8]>,
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§
§header: Cow<'a, [u8]>
Header data associated with the response as bytes
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 response to a typed response
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_header(&mut self, header: impl IntoIterator<Item = u8>)
pub fn set_header(&mut self, header: impl IntoIterator<Item = u8>)
Updates the header of the response to the given header
.
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.
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 more