pub enum ParsedEvent {
Show 17 variants
Bandwidth(BandwidthEvent),
Log(LogEvent),
Circuit(CircuitEvent),
Stream(StreamEvent),
OrConn(OrConnEvent),
AddrMap(AddrMapEvent),
BuildTimeoutSet(BuildTimeoutSetEvent),
Guard(GuardEvent),
NewDesc(NewDescEvent),
Signal(SignalEvent),
Status(StatusEvent),
ConfChanged(ConfChangedEvent),
NetworkLiveness(NetworkLivenessEvent),
CircuitBandwidth(CircuitBandwidthEvent),
ConnectionBandwidth(ConnectionBandwidthEvent),
HsDesc(HsDescEvent),
Unknown {
event_type: String,
content: String,
},
}Expand description
Enumeration of all parsed event types.
This enum provides a unified way to handle different event types
through pattern matching. Use ParsedEvent::parse to convert
raw event data into the appropriate variant.
§Parsing Events
Events are parsed from raw control protocol messages:
use stem_rs::events::ParsedEvent;
let event = ParsedEvent::parse("BW", "1024 2048", None)?;
match event {
ParsedEvent::Bandwidth(bw) => {
println!("Read: {}, Written: {}", bw.read, bw.written);
}
_ => {}
}§Unknown Events
Events that don’t match a known type are captured as
ParsedEvent::Unknown, preserving the raw content for
debugging or custom handling.
§Display
All variants implement Display to reconstruct
a human-readable representation of the event.
Variants§
Bandwidth(BandwidthEvent)
Aggregate bandwidth event (BW).
Log(LogEvent)
Log message event (DEBUG, INFO, NOTICE, WARN, ERR).
Circuit(CircuitEvent)
Circuit status change event (CIRC).
Stream(StreamEvent)
Stream status change event (STREAM).
OrConn(OrConnEvent)
OR connection status change event (ORCONN).
AddrMap(AddrMapEvent)
Address mapping event (ADDRMAP).
BuildTimeoutSet(BuildTimeoutSetEvent)
Circuit build timeout change event (BUILDTIMEOUT_SET).
Guard(GuardEvent)
Guard relay status change event (GUARD).
NewDesc(NewDescEvent)
New descriptor available event (NEWDESC).
Signal(SignalEvent)
Signal received event (SIGNAL).
Status(StatusEvent)
Status event (STATUS_GENERAL, STATUS_CLIENT, STATUS_SERVER).
ConfChanged(ConfChangedEvent)
Configuration changed event (CONF_CHANGED).
NetworkLiveness(NetworkLivenessEvent)
Network liveness event (NETWORK_LIVENESS).
CircuitBandwidth(CircuitBandwidthEvent)
Per-circuit bandwidth event (CIRC_BW).
ConnectionBandwidth(ConnectionBandwidthEvent)
Per-connection bandwidth event (CONN_BW).
HsDesc(HsDescEvent)
Hidden service descriptor event (HS_DESC).
Unknown
Unknown or unrecognized event type.
Implementations§
Source§impl ParsedEvent
impl ParsedEvent
Sourcepub fn parse(
event_type: &str,
content: &str,
lines: Option<&[String]>,
) -> Result<Self, Error>
pub fn parse( event_type: &str, content: &str, lines: Option<&[String]>, ) -> Result<Self, Error>
Parses raw event data into a typed event.
§Arguments
event_type- The event type keyword (e.g., “BW”, “CIRC”)content- The event content after the typelines- Optional multi-line content for events like CONF_CHANGED
§Supported Event Types
BW- Bandwidth eventsDEBUG,INFO,NOTICE,WARN,ERR- Log eventsCIRC- Circuit eventsSTREAM- Stream eventsORCONN- OR connection eventsADDRMAP- Address map eventsBUILDTIMEOUT_SET- Build timeout eventsGUARD- Guard eventsNEWDESC- New descriptor eventsSIGNAL- Signal eventsSTATUS_GENERAL,STATUS_CLIENT,STATUS_SERVER- Status eventsCONF_CHANGED- Configuration change eventsNETWORK_LIVENESS- Network liveness eventsCIRC_BW- Circuit bandwidth eventsCONN_BW- Connection bandwidth eventsHS_DESC- Hidden service descriptor events
§Errors
Returns Error::Protocol if the event content is malformed.
Unknown event types are returned as ParsedEvent::Unknown
rather than causing an error.
§Example
use stem_rs::events::ParsedEvent;
// Parse a bandwidth event
let event = ParsedEvent::parse("BW", "100 200", None)?;
// Parse a circuit event
let event = ParsedEvent::parse("CIRC", "1 BUILT $ABC...=relay", None)?;
// Unknown events are captured, not rejected
let event = ParsedEvent::parse("FUTURE_EVENT", "data", None)?;
assert!(matches!(event, ParsedEvent::Unknown { .. }));Sourcepub fn event_type(&self) -> &str
pub fn event_type(&self) -> &str
Trait Implementations§
Source§impl Clone for ParsedEvent
impl Clone for ParsedEvent
Source§fn clone(&self) -> ParsedEvent
fn clone(&self) -> ParsedEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more