about summary refs log tree commit diff
path: root/users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs
blob: 4ad177ad7a94e97f49cd4424821c5228adf9ba87 (plain) (blame)
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
use std::time::{SystemTime, UNIX_EPOCH};
use yew::prelude::*;

fn time_example() -> Html {
    let epoch = match SystemTime::now().duration_since(UNIX_EPOCH) {
        Ok(duration) => duration.as_secs(),
        Err(err) => {
            return html! {
                format!("failed to calculate duration: {}", err)
            }
        }
    };

    html! {
        <p>
          {"Seconds since epoch: "}{epoch}
        </p>
    }
}

struct App;
impl Component for App {
    type Message = ();
    type Properties = ();

    fn create(_: &Context<Self>) -> Self {
        Self
    }

    fn update(&mut self, _: &Context<Self>, _: Self::Message) -> bool {
        false
    }

    fn view(&self, _: &Context<Self>) -> Html {
        time_example()
    }
}

fn main() {
    yew::Renderer::<App>::new().render();
}