#[non_exhaustive]pub struct EventSubscription { /* private fields */ }Expand description
Declarative description of an ESL event subscription.
Captures the event format, event types, custom subclasses, and filters as a single unit. Useful for config-driven subscriptions and reconnection patterns where the caller needs to rebuild subscriptions from a saved description.
§Wire safety
Builder methods validate inputs against ESL wire injection risks.
Custom subclasses reject \n, \r, spaces, and empty strings.
Filter headers and values reject \n and \r.
§Example
use freeswitch_types::{EventSubscription, EventFormat, EslEventType, EventHeader};
let sub = EventSubscription::new(EventFormat::Plain)
.events(EslEventType::CHANNEL_EVENTS)
.event(EslEventType::Heartbeat)
.custom_subclass("sofia::register").unwrap()
.filter(EventHeader::CallDirection, "inbound").unwrap();
assert!(!sub.is_empty());
assert!(!sub.is_all());Implementations§
Source§impl EventSubscription
impl EventSubscription
Sourcepub fn new(format: EventFormat) -> Self
pub fn new(format: EventFormat) -> Self
Create an empty subscription with the given format.
Sourcepub fn all(format: EventFormat) -> Self
pub fn all(format: EventFormat) -> Self
Create a subscription for all events.
Sourcepub fn event(self, event: EslEventType) -> Self
pub fn event(self, event: EslEventType) -> Self
Add a single event type.
Sourcepub fn events<T: IntoIterator<Item = impl Borrow<EslEventType>>>(
self,
events: T,
) -> Self
pub fn events<T: IntoIterator<Item = impl Borrow<EslEventType>>>( self, events: T, ) -> Self
Add multiple event types (e.g. from group constants like EslEventType::CHANNEL_EVENTS).
Sourcepub fn custom_subclass(
self,
subclass: impl Into<String>,
) -> Result<Self, EventSubscriptionError>
pub fn custom_subclass( self, subclass: impl Into<String>, ) -> Result<Self, EventSubscriptionError>
Add a custom subclass (e.g. "sofia::register").
Returns Err if the subclass contains spaces, newlines, or is empty.
Sourcepub fn custom_subclasses(
self,
subclasses: impl IntoIterator<Item = impl Into<String>>,
) -> Result<Self, EventSubscriptionError>
pub fn custom_subclasses( self, subclasses: impl IntoIterator<Item = impl Into<String>>, ) -> Result<Self, EventSubscriptionError>
Add multiple custom subclasses.
Returns Err on the first invalid subclass.
Sourcepub fn filter(
self,
header: EventHeader,
value: impl Into<String>,
) -> Result<Self, EventSubscriptionError>
pub fn filter( self, header: EventHeader, value: impl Into<String>, ) -> Result<Self, EventSubscriptionError>
Add a filter with a typed header.
The header enum is always valid; only the value is validated.
Sourcepub fn filter_raw(
self,
header: impl Into<String>,
value: impl Into<String>,
) -> Result<Self, EventSubscriptionError>
pub fn filter_raw( self, header: impl Into<String>, value: impl Into<String>, ) -> Result<Self, EventSubscriptionError>
Add a filter with raw header and value strings.
Both header and value are validated against newline injection.
Sourcepub fn with_format(self, format: EventFormat) -> Self
pub fn with_format(self, format: EventFormat) -> Self
Change the event format.
Sourcepub fn format(&self) -> EventFormat
pub fn format(&self) -> EventFormat
The event format.
Sourcepub fn format_mut(&mut self) -> &mut EventFormat
pub fn format_mut(&mut self) -> &mut EventFormat
Mutable reference to the event format.
Sourcepub fn event_types(&self) -> &[EslEventType]
pub fn event_types(&self) -> &[EslEventType]
The subscribed event types.
Sourcepub fn event_types_mut(&mut self) -> &mut Vec<EslEventType>
pub fn event_types_mut(&mut self) -> &mut Vec<EslEventType>
Mutable access to the event types list.
Sourcepub fn custom_subclass_list(&self) -> &[String]
pub fn custom_subclass_list(&self) -> &[String]
The subscribed custom subclasses.
Sourcepub fn custom_subclasses_mut(&mut self) -> &mut Vec<String>
pub fn custom_subclasses_mut(&mut self) -> &mut Vec<String>
Mutable access to the custom subclasses list.
Sourcepub fn filters_mut(&mut self) -> &mut Vec<(String, String)>
pub fn filters_mut(&mut self) -> &mut Vec<(String, String)>
Mutable access to the filters list.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the subscription has no events and no custom subclasses.
Sourcepub fn to_event_string(&self) -> Option<String>
pub fn to_event_string(&self) -> Option<String>
Build the event string for the ESL event command.
Returns None if no events or custom subclasses are configured.
Returns Some("ALL") if EslEventType::All is present.
Otherwise returns space-separated event names with custom subclasses
appended after a CUSTOM token.
Trait Implementations§
Source§impl Clone for EventSubscription
impl Clone for EventSubscription
Source§fn clone(&self) -> EventSubscription
fn clone(&self) -> EventSubscription
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EventSubscription
impl Debug for EventSubscription
Source§impl<'de> Deserialize<'de> for EventSubscription
impl<'de> Deserialize<'de> for EventSubscription
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl PartialEq for EventSubscription
impl PartialEq for EventSubscription
Source§impl Serialize for EventSubscription
impl Serialize for EventSubscription
impl Eq for EventSubscription
impl StructuralPartialEq for EventSubscription
Auto Trait Implementations§
impl Freeze for EventSubscription
impl RefUnwindSafe for EventSubscription
impl Send for EventSubscription
impl Sync for EventSubscription
impl Unpin for EventSubscription
impl UnsafeUnpin for EventSubscription
impl UnwindSafe for EventSubscription
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.