Skip to main content

useceleris_client/
values.rs

1use std::fmt;
2
3/// Where a channel is in its lifecycle.
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub enum ChannelState {
6    /// Created and never connected.
7    Idle,
8
9    /// The first connection attempt is running.
10    Connecting,
11
12    /// A WebSocket is established. Nothing more is implied.
13    Connected,
14
15    /// The connection dropped and is being recovered.
16    Reconnecting,
17
18    /// Connecting or recovery failed. Connect may be called again.
19    Failed,
20
21    /// Close is shutting the connection down.
22    Closing,
23
24    /// Terminal. Create a new channel to connect again.
25    Closed,
26} // end enum ChannelState
27
28impl ChannelState {
29    /// The state's name, as the reference implementation spells it.
30    pub fn as_str(self) -> &'static str {
31        match self {
32            ChannelState::Idle => "idle",
33            ChannelState::Connecting => "connecting",
34            ChannelState::Connected => "connected",
35            ChannelState::Reconnecting => "reconnecting",
36            ChannelState::Failed => "failed",
37            ChannelState::Closing => "closing",
38            ChannelState::Closed => "closed",
39        }
40    } // end method as_str
41} // end impl ChannelState
42
43impl fmt::Display for ChannelState {
44    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
45        formatter.write_str(self.as_str())
46    } // end method fmt
47} // end impl Display for ChannelState
48
49/// Describes a delivery, beside its payload (MSG-01).
50#[derive(Clone, Debug, PartialEq, Eq)]
51pub struct MessageMetadata {
52    pub token_reference: String,
53    pub segment_id: String,
54
55    /// Always present: the publisher's, or one that the server assigned
56    /// (REV-01).
57    pub message_id: String,
58
59    /// Unix milliseconds.
60    pub timestamp: i64,
61} // end struct MessageMetadata
62
63/// A raw notice from the server: greetings, subscription acknowledgements and
64/// refusals, as human-readable prose. It names no segment and no command, so
65/// nothing may gate on its content.
66#[derive(Clone, Debug, PartialEq, Eq)]
67pub struct ServerNotice {
68    /// Unix milliseconds.
69    pub timestamp: i64,
70    pub payload: Vec<u8>,
71} // end struct ServerNotice
72
73/// One page of a segment's presence, every figure exactly as the server sent
74/// it. Past the last page `from` exceeds `to` and `connections` is empty; that
75/// is not an error.
76#[derive(Clone, Debug, PartialEq, Eq)]
77pub struct PresencePage {
78    pub segment_id: String,
79    pub total: i32,
80    pub per_page: i32,
81    pub current_page: i32,
82    pub from: i32,
83    pub to: i32,
84    pub connections: Vec<PresenceConnection>,
85} // end struct PresencePage
86
87/// One connection present in a segment. A token reference can hold several
88/// connections.
89#[derive(Clone, Debug, PartialEq, Eq)]
90pub struct PresenceConnection {
91    pub token_reference: String,
92    pub connection_id: String,
93
94    /// Unix milliseconds.
95    pub timestamp: i64,
96} // end struct PresenceConnection
97
98/// One connection that joined or left one segment (PRES-01).
99#[derive(Clone, Debug, PartialEq, Eq)]
100pub struct PresenceEvent {
101    pub segment_id: String,
102    pub token_reference: String,
103    pub connection_id: String,
104
105    /// `false` when the connection left.
106    pub joined: bool,
107
108    /// Unix milliseconds.
109    pub timestamp: i64,
110} // end struct PresenceEvent
111
112/// Reports a reconnect. Replay is a bounded window, not a durable log, so gaps
113/// and duplicates are always possible after one.
114#[derive(Clone, Debug, PartialEq, Eq)]
115pub struct RecoveryEvent {
116    /// The zero-based retry that succeeded.
117    pub retry_index: u32,
118
119    /// Always `true`.
120    pub possible_gaps: bool,
121
122    /// Always `true`.
123    pub possible_duplicates: bool,
124} // end struct RecoveryEvent