-
Notifications
You must be signed in to change notification settings - Fork 56
/
platform.rs
45 lines (38 loc) · 1.11 KB
/
platform.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crux_core::{render::Render, App};
use crux_platform::{Platform as PlatformCap, PlatformResponse};
use serde::{Deserialize, Serialize};
#[derive(Default)]
pub struct Platform {}
#[derive(Default, Serialize, Deserialize)]
pub struct Model {
pub platform: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum PlatformEvent {
Get,
Set(PlatformResponse),
}
pub struct PlatformCapabilities {
pub platform: PlatformCap<PlatformEvent>,
pub render: Render<PlatformEvent>,
}
impl App for Platform {
type Event = PlatformEvent;
type Model = Model;
type ViewModel = Model;
type Capabilities = PlatformCapabilities;
fn update(&self, msg: PlatformEvent, model: &mut Model, caps: &PlatformCapabilities) {
match msg {
PlatformEvent::Get => caps.platform.get(PlatformEvent::Set),
PlatformEvent::Set(platform) => {
model.platform = platform.0;
caps.render.render()
}
}
}
fn view(&self, model: &Model) -> Model {
Model {
platform: model.platform.clone(),
}
}
}