freya_core/platform.rs
1use std::rc::Rc;
2
3use crate::{
4 prelude::consume_root_context,
5 user_event::UserEvent,
6};
7
8#[derive(Clone)]
9pub struct Platform {
10 sender: Rc<dyn Fn(UserEvent)>,
11}
12
13impl Platform {
14 pub fn get() -> Self {
15 consume_root_context()
16 }
17
18 pub fn new(sender: impl Fn(UserEvent) + 'static) -> Self {
19 Self {
20 sender: Rc::new(sender),
21 }
22 }
23
24 pub fn send(&self, event: UserEvent) {
25 (self.sender)(event)
26 }
27}