#ui-framework #async #web-ui #wasm #gui #web-framework

async_ui_web

浏览器版的 Async UI

3 个不稳定版本

0.2.1 2023年10月10日
0.2.0 2023年7月24日
0.1.0 2022年10月4日

#1633 in 网页开发

MPL-2.0 许可证

225KB
4K SLoC

Async UI

crates.io crates.io

一个以 Futures 作为组件的网页 UI 框架。

概览(针对用户)

Async UI 是...

  • 简单;如果你了解 Futures 以及如何连接它们,你已经了解了 Async UI 的 90%。
  • 纯 async Rust;没有 DSL 或不透明的运行时 - 利用现有的 Async Rust 模式和生态系统。
  • 灵活;你可以直接访问整个 Web API(通过 web_sys)。

查看托管演示

现在开始!

概览(针对 UI 框架专家)

  • 异步作为 UI 运行时;应用是一个长时间运行的未来。
  • 组件是 Futures;组合是通过嵌套和连接 Futures 完成的。
  • UI 作为副作用;运行一个 Future 显示其 UI,丢弃它则移除该 UI。

了解更多关于该框架的信息

示例代码:Hello World

async fn hello_world() {
    "Hello World".render().await;
}

示例代码:异步控制流

async fn app() {
    let resource = loading_indicator(
        fetch_resource()
    ).await;
    show_resource(&resource).await;
}

示例代码:计数器

async fn counter() {
    let mut count = 0;
    let value_text = Text::new();
    let incr_button = Button::new();
    join((
        value_text.render(),
        incr_button.render("Increment".render()),
        async {
            loop {
                value_text.set_data(&count.to_string());
                incr_button.until_click().await;
                count += 1;
            }
        },
    ))
    .await;
}

依赖项

~12MB
~228K SLoC