4 releases (2 breaking)

0.3.0 Feb 15, 2023
0.2.0 Dec 15, 2022
0.1.1 Nov 18, 2022
0.1.0 Nov 18, 2022

#138 in WebAssembly

Download history 12/week @ 2022-11-28 2/week @ 2022-12-05 31/week @ 2022-12-12 26/week @ 2022-12-19 8/week @ 2022-12-26 6/week @ 2023-01-02 16/week @ 2023-01-09 7/week @ 2023-01-16 24/week @ 2023-01-23 31/week @ 2023-01-30 9/week @ 2023-02-06 52/week @ 2023-02-13 43/week @ 2023-02-20 6/week @ 2023-02-27 20/week @ 2023-03-06 14/week @ 2023-03-13

90 downloads per month
Used in 4 crates


1.5K SLoC

Rust 1K SLoC // 0.0% comments TypeScript 365 SLoC // 0.1% comments Java 19 SLoC Swift 16 SLoC

Crux — Cross-platform app development in Rust

Crate Info API Docs

Crux helps you share your app's business logic and behavior across mobile (iOS and Android) and web, as a single, reusable core built with Rust.

Unlike React Native, but like Kotlin Multi-platform Mobile, the user interface layer is built natively, with modern declarative UI frameworks such as SwiftUI, Jetpack Compose and React/Vue or a Wasm based framework (like Yew) on the web.

The UI layer is as thin as it can be, and all other work is done by the shared core. The interface with the core has static type checking across languages.

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! :-)

Getting Started

Architectural Overview

Logical architecture

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.

Side-effect-free core

In the above diagram, the inner "Core" is compiled and linked to the outer "Shell" on each platform as a library:

  • On iOS as a native static library
  • On Android as a dynamic library using Java Native Access
  • In a browser as a WebAssembly module

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 handle
  • Model — describes the internal state of the application
  • ViewModel — represents information that should be displayed to the user

The 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(
    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.

Application Shell

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.


~85K SLoC