about summary refs log tree commit diff
path: root/users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-09-02T10·02+0300
committertazjin <tazjin@tvl.su>2023-09-02T18·20+0000
commit4ef86040ddc4f5f63465776f1dc984163a449bbe (patch)
treed0896cbba707a9b76db2160b66e85977e1983f58 /users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs
parent0e01e91174814fee7d1b3685933d5a974a60bc74 (diff)
feat(tazjin/presentations): add (intentionally) broken WASM demo r/6542
This demonstrates a Rust stdlib call that just causes runtime panics
on WASM, for explaining the problems with porting Tvixbolt.

Change-Id: Ief974f1bba509fdac4b9bc9f862ee8f4dfc5158e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9206
Tested-by: BuildkiteCI
Reviewed-by: Mark Shevchenko <markshevchenko@gmail.com>
Autosubmit: tazjin <tazjin@tvl.su>
Diffstat (limited to 'users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs')
-rw-r--r--users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs b/users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs
new file mode 100644
index 000000000000..4ad177ad7a94
--- /dev/null
+++ b/users/tazjin/presentations/tvix-eval-2023/wasm-fs-demo/src/main.rs
@@ -0,0 +1,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();
+}