graphql_ws_client_old_protocol/websockets.rs
1//! Contains traits to provide support for various underlying websocket clients.
2
3/// An abstraction around WebsocketMessages
4///
5/// graphql-ws-client doesn't implement the websocket protocol itself.
6/// This trait provides part of the integration with websocket client libraries.
7pub trait WebsocketMessage: std::fmt::Debug {
8 /// The `Error` type for this websocket client.
9 type Error: std::error::Error + Send + 'static;
10
11 /// Constructs a new message with the given text
12 fn new(text: String) -> Self;
13
14 /// Returns the text (if there is any) contained in this message
15 fn text(&self) -> Option<&str>;
16
17 /// Returns the text (if there is any) of the error
18 fn error_message(&self) -> Option<String>;
19
20 /// Returns true if this message is a websocket ping.
21 fn is_ping(&self) -> bool;
22
23 /// Returns true if this message is a websocket pong.
24 fn is_pong(&self) -> bool;
25
26 /// Returns true if this message is a websocket close.
27 fn is_close(&self) -> bool;
28}