Crates.io | crux_core |
lib.rs | crux_core |
version | 0.10.0 |
source | src |
created_at | 2022-11-18 16:48:24.51214 |
updated_at | 2024-10-23 09:29:03.590592 |
description | Cross-platform app development in Rust |
homepage | |
repository | https://github.com/redbadger/crux/ |
max_upload_size | |
id | 717987 |
size | 483,442 |
Learn how to use Crux in your project.
Follow the readme in the project's repository on Github.
Read the API documentation
Watch the introductory talk at the recent Rust Nation 2023 conference in London.
You can also join the friendly conversation on our Zulip channel.
Note, that Crux is experimental and currently under active development (probably not ready for use in production apps just yet). However, the master branch should always be working well, and we will try to keep the examples and documentation up to date as we go. We do think that the API has now settled, so have a play! :-)
The fundamental architectural concept is the strict separation of pure computational tasks from tasks that cause side effects. This is similar to the way Elm works.
In the above diagram, the inner "Core" is compiled and linked to the outer "Shell" on each platform as a library:
In fact, because WebAssembly (Wasm) is one of the compilation targets, the core must remain side-effect free, due to the sandboxed nature of the Wasm runtime environment.
As such, the core is completely isolated and secure against software supply-chain attacks, as it has no access to any external APIs. All it can do is perform pure calculations and keep internal state.
Following the Elm architecture, the core defines the key component types within the application:
Event
— an enum
describing the events which the core can handleModel
— describes the internal state of the applicationViewModel
— represents information that should be displayed to the userThe former two are tied together by the update
function, familiar from Elm,
Redux or other event sourcing architectures, which currently has this type
signature:
fn update(
&self,
event: Event,
model: &mut Model,
capabilities: &Capabilities,
)
The job of the update
function is to process an Event
, update the model
accordingly, and potentially request some side-effects using capabilities.
The enclosing platform native "Shell" is written using the language appropriate for the platform, and acts as the runtime environment within which all the non-pure tasks are performed. From the perspective of the core, the shell is the platform on which the core runs.