openvpn_mgmt_codec/stream_mode.rs
1use std::fmt;
2
3/// Mode selector for commands that share the on/off/all/on-all/N grammar.
4/// This is used by `log`, `state`, and `echo`, all of which support
5/// identical sub-commands.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum StreamMode {
8 /// Enable real-time notifications.
9 On,
10
11 /// Disable real-time notifications.
12 Off,
13
14 /// Dump the entire history buffer.
15 All,
16
17 /// Atomically enable real-time notifications AND dump history.
18 /// This guarantees no messages are missed between the dump and
19 /// the start of real-time streaming.
20 OnAll,
21
22 /// Show the N most recent history entries.
23 Recent(u32),
24}
25
26impl fmt::Display for StreamMode {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 Self::On => f.write_str("on"),
30 Self::Off => f.write_str("off"),
31 Self::All => f.write_str("all"),
32 Self::OnAll => f.write_str("on all"),
33 Self::Recent(n) => write!(f, "{n}"),
34 }
35 }
36}