Skip to main content

plexus_client/
event.rs

1//! What a typed client hands its caller.
2
3/// One event of a typed Plexus call.
4///
5/// `E` is the activation's own event enum — `TicketsEvent`, not a
6/// hand-mirrored copy of it. That identity is the whole zero-drift argument:
7/// rename a field on the server type and every consumer of this stream stops
8/// compiling.
9///
10/// Terminal states are deliberately *not* variants here: normal completion
11/// is the stream ending, and both error layers are the `Err` half of
12/// `Result<ClientEvent<E>, ClientError>`.
13#[derive(Debug, Clone, PartialEq)]
14pub enum ClientEvent<E> {
15    /// A payload event from the activation.
16    Data(E),
17    /// A progress report. Carries no payload.
18    Progress {
19        message: String,
20        percentage: Option<f32>,
21    },
22}
23
24impl<E> ClientEvent<E> {
25    /// The payload, if this is a data event.
26    pub fn into_data(self) -> Option<E> {
27        match self {
28            ClientEvent::Data(e) => Some(e),
29            ClientEvent::Progress { .. } => None,
30        }
31    }
32
33    /// Borrow the payload, if this is a data event.
34    pub fn data(&self) -> Option<&E> {
35        match self {
36            ClientEvent::Data(e) => Some(e),
37            ClientEvent::Progress { .. } => None,
38        }
39    }
40
41    /// `true` for [`ClientEvent::Progress`].
42    pub fn is_progress(&self) -> bool {
43        matches!(self, ClientEvent::Progress { .. })
44    }
45}