1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Contains traits to provide support for various underlying websocket clients.

/// An abstraction around WebsocketMessages
///
/// graphql-ws-client doesn't implement the websocket protocol itself.
/// This trait provides part of the integration with websocket client libraries.
pub trait WebsocketMessage: std::fmt::Debug {
    /// The `Error` type for this websocket client.
    type Error: std::error::Error + Send + 'static;

    /// Constructs a new message with the given text
    fn new(text: String) -> Self;

    /// Returns the text (if there is any) contained in this message
    fn text(&self) -> Option<&str>;

    /// Returns the text (if there is any) of the error
    fn error_message(&self) -> Option<String>;

    /// Returns true if this message is a websocket ping.
    fn is_ping(&self) -> bool;

    /// Returns true if this message is a websocket pong.
    fn is_pong(&self) -> bool;

    /// Returns true if this message is a websocket close.
    fn is_close(&self) -> bool;
}