1
//! The `TorEvent` and `TorEventKind` types.
2
use serde::{Deserialize, Serialize};
3

            
4
/// An event emitted by some Tor-related crate.
5
1
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
6
#[non_exhaustive]
7
pub 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]
23
pub enum TorEventKind {
24
    /// Identifier for [`TorEvent::Empty`].
25
    Empty = 0,
26
}
27

            
28
impl TorEvent {
29
    /// Get the corresponding `TorEventKind` for this event.
30
3
    pub fn kind(&self) -> TorEventKind {
31
3
        match self {
32
3
            TorEvent::Empty => TorEventKind::Empty,
33
3
        }
34
3
    }
35
}