tor_events/
events.rs

1//! The `TorEvent` and `TorEventKind` types.
2use serde::{Deserialize, Serialize};
3
4/// An event emitted by some Tor-related crate.
5#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum TorEvent {
8    /// An event with no data, used for testing purposes.
9    Empty,
10}
11
12/// An opaque type describing a variant of `TorEvent`.
13///
14/// Variants of this enum have the same name as variants of `TorEvent`, but no data. This
15/// is useful for functions like `TorEventReceiver::subscribe`, which lets you choose which
16/// variants you want to receive.
17//
18// Internally, these are indices into the `EVENT_SUBSCRIBERS` array.
19// NOTE: Update EVENT_KIND_COUNT when adding new events!!
20#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
21#[repr(usize)]
22#[non_exhaustive]
23pub enum TorEventKind {
24    /// Identifier for [`TorEvent::Empty`].
25    Empty = 0,
26}
27
28impl TorEvent {
29    /// Get the corresponding `TorEventKind` for this event.
30    pub fn kind(&self) -> TorEventKind {
31        match self {
32            TorEvent::Empty => TorEventKind::Empty,
33        }
34    }
35}