pub struct Frame {
pub join_ref: Option<String>,
pub reference: Option<String>,
pub topic: String,
pub event: String,
pub payload: Payload,
}Expand description
A Phoenix Channels v2 JSON frame.
The serialized representation is
[join_ref, ref, topic, event, payload].
Fields§
§join_ref: Option<String>Reference of the channel join generation, when present.
reference: Option<String>Reference used to correlate a push and reply, when present.
topic: StringChannel topic or the special phoenix heartbeat topic.
event: StringPhoenix or application-defined event name.
payload: PayloadJSON, binary, or reply payload carried by the frame.
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn new(
join_ref: Option<String>,
reference: Option<String>,
topic: impl Into<String>,
event: impl Into<String>,
payload: impl Into<Payload>,
) -> Self
pub fn new( join_ref: Option<String>, reference: Option<String>, topic: impl Into<String>, event: impl Into<String>, payload: impl Into<Payload>, ) -> Self
Creates a protocol frame from its v2 serializer fields.
Sourcepub fn encode_text(&self) -> Result<String, FrameCodecError>
pub fn encode_text(&self) -> Result<String, FrameCodecError>
Encodes this frame using Phoenix’s JSON v2 representation.
Binary payloads must be encoded with crate::Codec instead.
Sourcepub fn decode_text(input: &str) -> Result<Self, FrameCodecError>
pub fn decode_text(input: &str) -> Result<Self, FrameCodecError>
Decodes a Phoenix JSON v2 frame.
Sourcepub fn route<R: EventRoute>(&self) -> Result<Option<R::Output>, PayloadError>
pub fn route<R: EventRoute>(&self) -> Result<Option<R::Output>, PayloadError>
Decodes this frame’s JSON payload when its event matches R::EVENT.
Returns Ok(None) for a different event.
Trait Implementations§
impl StructuralPartialEq for Frame
Auto Trait Implementations§
impl Freeze for Frame
impl RefUnwindSafe for Frame
impl Send for Frame
impl Sync for Frame
impl Unpin for Frame
impl UnsafeUnpin for Frame
impl UnwindSafe for Frame
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