ParsedEvent

Enum ParsedEvent 

Source
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.

Fields

§event_type: String

The event type string.

§content: String

The raw event content.

Implementations§

Source§

impl ParsedEvent

Source

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 type
  • lines - Optional multi-line content for events like CONF_CHANGED
§Supported Event Types
  • BW - Bandwidth events
  • DEBUG, INFO, NOTICE, WARN, ERR - Log events
  • CIRC - Circuit events
  • STREAM - Stream events
  • ORCONN - OR connection events
  • ADDRMAP - Address map events
  • BUILDTIMEOUT_SET - Build timeout events
  • GUARD - Guard events
  • NEWDESC - New descriptor events
  • SIGNAL - Signal events
  • STATUS_GENERAL, STATUS_CLIENT, STATUS_SERVER - Status events
  • CONF_CHANGED - Configuration change events
  • NETWORK_LIVENESS - Network liveness events
  • CIRC_BW - Circuit bandwidth events
  • CONN_BW - Connection bandwidth events
  • HS_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 { .. }));
Source

pub fn event_type(&self) -> &str

Returns the event type string for this event.

This returns the canonical event type keyword as used in SETEVENTS commands and event responses.

§Example
let event = ParsedEvent::parse("BW", "100 200", None)?;
assert_eq!(event.event_type(), "BW");

Trait Implementations§

Source§

impl Clone for ParsedEvent

Source§

fn clone(&self) -> ParsedEvent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParsedEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ParsedEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.