pub enum Payload {
Json(Value),
Binary(Vec<u8>),
Reply {
status: String,
response: Box<Payload>,
},
}Expand description
Payload carried by a Phoenix protocol frame.
Variants§
Json(Value)
An ordinary JSON payload.
Binary(Vec<u8>)
An opaque binary payload.
Reply
The status and response object inside a phx_reply frame.
Implementations§
Source§impl Payload
impl Payload
Sourcepub fn as_json(&self) -> Option<&Value>
pub fn as_json(&self) -> Option<&Value>
Borrows the JSON value when this is Payload::Json.
Sourcepub fn as_binary(&self) -> Option<&[u8]>
pub fn as_binary(&self) -> Option<&[u8]>
Borrows the bytes when this is Payload::Binary.
Sourcepub fn into_json(self) -> Result<Value, Self>
pub fn into_json(self) -> Result<Value, Self>
Consumes this payload and returns its JSON value.
Returns the original payload when it is not JSON.
Sourcepub fn into_binary(self) -> Result<Vec<u8>, Self>
pub fn into_binary(self) -> Result<Vec<u8>, Self>
Consumes this payload and returns its binary bytes.
Returns the original payload when it is not binary.
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, PayloadError>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, PayloadError>
Deserializes a JSON payload into T.
Trait Implementations§
impl StructuralPartialEq for Payload
Auto Trait Implementations§
impl Freeze for Payload
impl RefUnwindSafe for Payload
impl Send for Payload
impl Sync for Payload
impl Unpin for Payload
impl UnsafeUnpin for Payload
impl UnwindSafe for Payload
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
Mutably borrows from an owned value. Read more