Full-Rust Web3 application toolkit focus on
ECS based event-driven development.
Powered by Bevy game engine.
From desktop apps to the Metaverse.
```rust, no_run use dip::prelude::*;
fn main() {
App::new()
.insertresource(WindowDescriptor {
title: "dip Plugin Example".tostring(),
..Default::default()
})
.add_plugin(DesktopPlugin::
fn Root(cx: Scope) -> Element { cx.render(rsx! { h1 { "Hello, World !" } }) } ```
WARNING:
dip
is still in the very early stages of development.
v0.1
is totally a different application. I wanted to make a cross-platform text editor but ended up making this framework.
Code example
```toml
[dependencies] dip = { version = "0.2", features = ["desktop"] } ```
```rust, no_run use dip::prelude::*;
fn main() {
App::new()
.insertresource(WindowDescriptor {
title: "Desktop App".tostring(),
..Default::default()
})
.add_plugin(DesktopPlugin::
fn Root(cx: Scope) -> Element { let name = usestate(&cx, || "world".tostring());
cx.render(rsx! {
h1 { "Hello, {name} !" }
input {
value: "{name}",
oninput: |e| {
name.set(e.value.to_string());
},
}
})
} ```
Code example
```toml
[dependencies] dip = { version = "0.2", features = ["cli"] } clap = { version = "3.2", features = ["derive"] } ```
```rust, no_run use dip::{bevy::log::LogPlugin, prelude::*};
fn main() {
App::new()
.addplugin(CliPlugin::
struct Cli {
root_arg: Option
#[clap(short, long)]
path: Option<String>,
#[clap(subcommand)]
action: Action,
}
pub enum Action {
// Named variant
Hello { name: Option
pub struct Hello2Args {
name: Option
fn logrootarg(cli: Res
fn logpathflag(cli: Res
fn handlehello(mut events: EventReader
fn handletask(mut events: EventReader
fn handle_ping(mut events: EventReader
```sh cargo run -- --help
dip-cli-example 0.1.0 Junichi Sugiura Example binary project to showcase CliPlugin usage.
USAGE:
cli [OPTIONS] [ROOT_ARG]
ARGS:
OPTIONS:
-h, --help Print help information
-p, --path
SUBCOMMANDS: hello hello2 help Print this message or the help of the given subcommand(s) ping
```
Code example
```toml
[dependencies] dip = { version = "0.2", features = ["desktop"] }
bevy_ecs = "0.8" ```
```rust, no_run use dip::prelude::*;
fn main() {
App::new()
// Step 7. Put it all together
.addplugin(DesktopPlugin::
// Step 1: Define UiState // Each field represents root state. You can create multiple of them. // This macro generates UiState enum and UiStatePlugin which will be used in step 7.
struct UiState { name: Name, }
// Make sure to wrap primitive types or common type such as String with named struct or enum. // You need to distinguish types in order to query specific root state in step 4 (system).
pub struct Name { value: String, }
// This is how you define default value for Name root state. impl Default for Name { fn default() -> Self { Self { value: "world".to_string(), } } }
// Step 2. Define actions // Create as many as actions with struct or enum.
pub struct UpdateName { value: String, }
// Step 3. Implement action creators // Each method needs to return one of actions that you defined in step 2. // This macro derives UiActionPlugin and UiAction which will be used in step 7.
impl ActionCreator { fn update_name(value: String) -> UpdateName { UpdateName { value } } }
// Step 4. Implement systems to handle each action defined in step 2.
// System is like reducer in Redux but more flexible.
fn update_name(mut events: EventReader
fn Root(cx: Scope) -> Element { // Step 5. Select state let name = use_read(&cx, NAME);
let window = use_window::<UiAction, NoAsyncAction>(&cx);
cx.render(rsx! {
h1 { "Hello, {name.value} !" }
input {
value: "{name.value}",
oninput: |e| {
// Step 6. Dispatch the action !
window.send(UiAction::update_name(e.value.to_string()));
},
}
})
} ```
https://github.com/bevyengine/bevy - Data-driven game engine based on Entity Component System(ECS) design pattern - Flexible Plugin design - Plugin ecosystem
Bevy is a cutting-edge game engine in Rust based on Entity Component System(ECS) design pattern. Think of it as a global state management tool like Redux but much more performant because all systems will run as parallel as possible. Thanks to its plugin system, there's already a handful of third-party Bevy plugins out there. Imagine implementing core logic as CorePlugin
separated from UI layer. You may start with dip::desktop
to build desktop application. Then let's say you want to release a metaverse edition at some point in the future, it's as simple as swapping UI plugin to Bevy's 3d rendering plugin while still using the same CorePlugin.
Tao is a window manager and the fork of winit
. DesktopPlugin
depends on this library to render webview. And the webview is powered by WRY which is essentailly a Rust wrapper around OS specific webview.
If you want to write frontend in any languages other than Rust, then Tauri is a better fit! If you want to go full Rust, then that's where dip
shines.
https://github.com/DioxusLabs/dioxus - Cross-platform (macOS, Linux, Windows, TUI, etc.) - React-like declarative UI library - Virtual dom is 3x faster than React - Minimum bundle size is around 20x lighter than Electron (8 MB vs 160MB)
Dioxus is a cross-platform declarative UI library. It provides familiar features that React developer expects such as component, state, props, hooks, global state, and router. If you familiar with any modern state driven UI framework, you should be able to read or write Dioxus components without knowing Rust.
Make sure to install all prerequisites for Tauri. - Prerequisites
sh
gh repo clone diptools/dip
cd dip
sh
cargo run --example counter --features desktop
Find more in examples/ directory.
```sh cargo install dip
cargo install --path . ```
sh
dip build -p examples/todomvc
sh
cargo run -p todomvc