Proc macro preparation
This commit is contained in:
28
simconnect-sdk/src/domain/notification.rs
Normal file
28
simconnect-sdk/src/domain/notification.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use crate::{AirportData, Event, SimConnectObjectExt};
|
||||
|
||||
pub enum Notification {
|
||||
Open,
|
||||
Event(Event),
|
||||
Data(NotificationData),
|
||||
AirportList(Vec<AirportData>),
|
||||
Quit,
|
||||
Exception(u32),
|
||||
}
|
||||
|
||||
pub struct NotificationData {
|
||||
pub(crate) type_id: String,
|
||||
pub(crate) data_addr: *const u32,
|
||||
}
|
||||
|
||||
impl NotificationData {
|
||||
pub fn try_into<T: SimConnectObjectExt>(&self) -> Option<T> {
|
||||
let type_id: String = std::any::type_name::<T>().into();
|
||||
|
||||
if self.type_id == type_id {
|
||||
let data: &T = unsafe { std::mem::transmute_copy(&self.data_addr) };
|
||||
Some(data.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user