leaprs/events/
connection_event.rs1use derive_deref::Deref;
2use leap_sys::LEAP_CONNECTION_EVENT;
3
4use crate::ServiceState;
5
6#[doc = " \\ingroup Structs"]
7#[doc = " Received from LeapPollConnection() when a connection to the Ultraleap Tracking Service is established."]
8#[doc = " @since 3.0.0"]
9#[derive(Deref, Clone, Copy)]
12pub struct ConnectionEventRef<'a>(pub(crate) &'a LEAP_CONNECTION_EVENT);
13
14impl<'a> ConnectionEventRef<'a> {
15 #[doc = " A combination of eLeapServiceDisposition flags. @since 3.1.3"]
16 pub fn flags(&self) -> ServiceState {
17 ServiceState::from_bits_truncate(self.flags)
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use crate::tests::*;
24 use crate::*;
25
26 #[test]
27 fn connection_event_test() {
28 let mut connection =
29 Connection::create(ConnectionConfig::default()).expect("Failed to connect");
30 connection.open().expect("Failed to open the connection");
31 let _flags = connection
32 .wait_for(|e| match e {
33 EventRef::Connection(e) => Some(e.flags()),
34 _ => None,
35 })
36 .expect("Did not receive a connection event.");
37 }
38}