Struct Event

Source
pub struct Event { /* private fields */ }

Implementations§

Source§

impl Event

Source

pub fn get(&self, k: &str) -> Option<&String>

Examples found in repository?
examples/dump-events.rs (line 35)
14fn main() -> std::io::Result<()> {
15    let args: Vec<String> = env::args().collect();
16    let host = &args[1];
17    let event = &args[2];
18    let mut stream = TcpStream::connect(host)?;
19
20    let conn = Connection::new(stream);
21    let mut client = Client::new(conn);
22    let mut stats = Stats{
23        event_per_tick: 0,
24        events_counts_per_sec: HashMap::new()
25    };
26
27    client.auth("cloudpbx").expect("fails to authenticate");
28    client.event(event).expect("fails enabling events");
29
30    let mut now = std::time::Instant::now();
31    let notify_on_secs = std::time::Duration::from_secs(1);
32
33    loop {
34        let event: Event = client.pull_event().unwrap();
35        let event_name = event.get("Event-Name").unwrap().to_string();
36
37        stats.event_per_tick += 1;
38        if event_name == "CUSTOM" {
39            let event_subclass = event.get("Event-Subclass").unwrap().to_string();
40            let mut event_name = format!("{}:{}", event_name, event_subclass);
41            if let Some(action) = event.get("CC-Action") {
42                event_name = format!("{}:{}", event_name, action.to_string())
43            }
44            if let Some(counter) = stats.events_counts_per_sec.get_mut(&event_name) {
45                *counter += 1;
46            } else {
47                stats.events_counts_per_sec.insert(event_name, 1);
48            }
49        } else {
50            if let Some(counter) = stats.events_counts_per_sec.get_mut(&event_name) {
51                *counter += 1;
52            } else {
53                stats.events_counts_per_sec.insert(event_name, 1);
54            }
55        }
56
57        if now.elapsed() >= notify_on_secs {
58            let stamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
59            println!("{} {:?} {:?}", stamp.as_secs(), now.elapsed(), stats);
60
61            now = std::time::Instant::now();
62            stats.event_per_tick = 0;
63            stats.events_counts_per_sec.clear();
64        }
65    }
66    
67    Ok(())
68}
More examples
Hide additional examples
examples/stats-events.rs (line 35)
14fn main() -> std::io::Result<()> {
15    let args: Vec<String> = env::args().collect();
16    let host = &args[1];
17    let event = &args[2];
18    let mut stream = TcpStream::connect(host)?;
19
20    let conn = Connection::new(stream);
21    let mut client = Client::new(conn);
22    let mut stats = Stats{
23        event_per_tick: 0,
24        events_counts_per_tick: HashMap::new()
25    };
26
27    client.auth("cloudpbx").expect("fails to authenticate");
28    client.event(event).expect("fails enabling events");
29
30    let mut now = std::time::Instant::now();
31    let notify_on_secs = std::time::Duration::from_secs(1);
32
33    loop {
34        let event: Event = client.pull_event().unwrap();
35        let event_name = event.get("Event-Name").unwrap().to_string();
36
37        stats.event_per_tick += 1;
38        if event_name == "CUSTOM" {
39            let event_subclass = event.get("Event-Subclass").unwrap().to_string();
40            let mut event_name = format!("{}:{}", event_name, event_subclass);
41            if let Some(action) = event.get("CC-Action") {
42                event_name = format!("{}:{}", event_name, action.to_string())
43            }
44            if let Some(counter) = stats.events_counts_per_tick.get_mut(&event_name) {
45                *counter += 1;
46            } else {
47                stats.events_counts_per_tick.insert(event_name, 1);
48            }
49        } else {
50            if let Some(counter) = stats.events_counts_per_tick.get_mut(&event_name) {
51                *counter += 1;
52            } else {
53                stats.events_counts_per_tick.insert(event_name, 1);
54            }
55        }
56
57        if now.elapsed() >= notify_on_secs {
58            let stamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
59            println!("{} {:?} {:?}", stamp.as_secs(), now.elapsed(), stats);
60
61            now = std::time::Instant::now();
62            stats.event_per_tick = 0;
63            stats.events_counts_per_tick.clear();
64        }
65    }
66    
67    Ok(())
68}
Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

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

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

impl Into<HashMap<String, String>> for Event

Source§

fn into(self) -> HashMap<String, String>

Converts this type into the (usually inferred) input type.
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Event

Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

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