A Platform-less, Runtime-less Actor Computing Model

Overview

CrossBus

A Platform-Less, Runtime-Less Actor Computing Model

API Document crates.io

Overview

CrossBus is an implementation of Actor Computing Model, with the concept that

  • Runtime-less

    crossbus neither provide runtime for app execution nor access the system interface abstraction. no built-in runtime, but any runtime is allowed,
    the system-provided / third-party's / that from FFI-binding all work. Last but not least, even a bare-bone noop-waker executor can do.

    runtime-located features like concurrency, network and I/O are up to implementor.

  • Bare-Metal Compatible

    crossbus links to no system libraries, no libc, and a few upstream libraries enbale you run rust code on bare metal.

    the examples folder contains some demos to use crossbus.

  • Platform-less by Runtime-less

    take the advantage of runtime-less, crossbus is able to bypass the limitation of runtime implementor and system interface abstraction and go right straight to manipulate task directly. Only a simple and dummy future executor(look at the no-std example) is sufficed to run crossbus. This is the primary concept of crossbus to run across many platforms or without platforms.

  • Future-oriented Routine and Events

    the futures way to execute task is retained even without runtime thanks to rust. crossbus defines a set of types and traits to allow asynchronous tasks manipulation.

  • Real-time Execution Control

    taking the advantage of the design of future routine, each poll and events alongside can be intercepted for each spawned task during execution, with which more execution control is possible.

Currently crossbus is in its alpha version, all APIs and architecture is not stable yet, and evolves very quickly.

Documentation

Feature Flags

To reduce code redundancy and speed up compilation, crossbus use feature flag to mark the necessary modules/functions, Currently here are some supported Features:

  • core/no-std: the default feature, bare-metal compatible
  • std: rust std library dependent
  • derive: enable #[derive(Message)] and #[crossbus::main(...)]
  • log: enable logging out states and infos during runtime
  • time: enable Actor to known time when blocking/delaying some duration
  • rt: enable use some common convenient runtime
  • tokio: convenience to use bare tokio-based runtime
  • async-std: convenience to use async-std-based runtime
  • wasm32: convenience to use wasm-bindgen-futures-based runtime
  • unstable: marker for unstable feature
  • time-metric: enabled with unstable and time, numerical timing feature
  • force-poll: enabled with unstable, time-dependent to periodically wakeup future polling

How to Use

First of all, add crossbus to Cargo.toml of project

[dependencies]
crossbus = "0.0.6-a"

Types and Imports

define Some types and methods according to your business logic.

let's say a actor to add some number up, Okay, then the message should be numbers the actor should know the result after adding.

use crossbus::prelude::*;

struct Num(uisze);
impl Message for Num {}

struct CrossBus {
    sum: isize
}

Actor Implementation

the actor should be created before using it

we tell crossbus how to create it

impl Actor for CrossBus {
    type Message = Num;
...
    fn create(ctx: &mut Context<Self>) -> Self {
        Self { sum: 0, }
    }
...
}

Message Action & Reaction

Okay, How the actor respond when the message comes? we should tell crossbus.

    ...
    fn action(&mut self, msg: Self::Message, ctx: &mut Context<Self>) {
        self.sum += msg.0;
    }
    ...

So far so good, but how to obtain the final result

it can be available when the actor process all messages and stopped, right?

    ...
    fn stopped(&mut self, _: &mut Context<Self>) {
        println!("final sum: {}", self.sum);
    }
    ...

Done. Congratulation! You just knew the basic routine to use crossbus. the Full code see below.

Example

Here presents a simple demo to sum numbers.

For more examples, you can go to the examples folder and clone the repo and run them locally.

use crossbus::prelude::*;

struct Num(uisze);
impl Message for Num {}

struct CrossBus {
    sum: isize
}
impl Actor for CrossBus {
    type Message = Num;

    fn create(ctx: &mut Context<Self>) -> Self {
        Self { sum: 0, }
    }

    fn action(&mut self, msg: Self::Message, ctx: &mut Context<Self>) {
        self.sum += msg.0;
    }

    fn stopped(&mut self, _: &mut Context<Self>) {
        println!("final sum: {}", self.sum);
        assert_eq!(self.sum, 7);
    }

}

#[main(runtime = tokio)]
async fn main() {
    let (addr, id) = CrossBus::start();
		println!("actor {} started", id);
    let sender = addr.sender();
    sender.send(Num(1)).unwrap();
    sender.send(Num(2)).unwrap();
    sender.send(Num(4)).unwrap();
}

Contributing

Feel Free to Contribute! All issues / bugs-report / feature-request / etc are welcome!

References

You might also like...
Salty and Sweet one-line Rust Runtime Optimization Library

SAS SAS (Salty-And-Sweet) is an one-line Rust runtime optimization library. Features NUMA-aware rayon: numa feature should be enabled If you have 1 NU

A heap allocated runtime for deeply recursive algorithms.

Reblessive A heap allocated runtime for deeply recursive algorithms. Turn your cursed recursive algorithm into a blessed heap allocated structure whic

A cloud-native distributed serverless workers platform.

rusty-workers A cloud-native distributed serverless workers platform. Features JavaScript and WebAssembly engine powered by V8 Fetch API Highly scalab

Cross-platform GUI for youtube-dl made with Iced

youtube-dl-gui Cross-platform GUI for youtube-dl made with Iced. Installation Before you install this crate, make sure you have youtube-dl and FFmpeg

`memory_pages` is a small library provinig a cross-platform API to request pages from kernel with certain premisions

memory_pages: High level API for low level memory management While using low-level memory management in a project can provide substantial benefits, it

Platform independent data channels for WebRTC/Rust.

preach Platform independent data channels Preach provides an abstraction for WebRTC data channels that runs on both native and web platforms. Preach m

A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other

Qreeket (pronounced "cricket") A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other. As the

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.
Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer.

Multi-platform desktop app to download and run Large Language Models(LLM) locally in your computer 🔗 Download | Give it a Star ⭐ | Share it on Twitte

Pbot - pan93412's extensible userbot, which is full-documented, enginnered and based on Actor model.

pbot pan93412's extensible user bot, which is full-documented, engineered and based on Actor model. Usage Run cargo run --release [--features modules

Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.
Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.

What is Tight Model Format The main goal of the tmf project is to provide a way to save 3D game assets compressed in such a way, that there are no not

RISC Zero is a zero-knowledge verifiable general computing platform based on zk-STARKs and the RISC-V microarchitecture.

RISC Zero WARNING: This software is still experimental, we do not recommend it for production use (see Security section). RISC Zero is a zero-knowledg

Actor framework for Rust.

Actix Actor framework for Rust Documentation User Guide API Documentation API Documentation (master branch) Features Async and sync actors Actor commu

wasm actor system based on lunatic

Wactor WASM actor system based on lunatic. Actors run on isolated green threads. They cannot share memory, and communicate only through input and outp

Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.
Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.

Actix codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API. ❗ (2021/05/13) This cod

Ector is an open source async, no-alloc actor framework for embedded devices

Ector is an open source async, no-alloc actor framework for embedded devices. Ector is an open source async, no-alloc actor framework for embedded dev

A partial actor pattern with a global orchestrator.

orchestra The orchestra pattern is a partial actor pattern, with a global orchestrator regarding relevant work items. proc-macro The proc macro provid

Spine runtime for Rust (and wasm!) transpiled from the official C Runtime.

rusty_spine Spine runtime for Rust (and wasm!) transpiled from the official C Runtime. Supports Spine 4.1. [dependencies] rusty_spine = "0.4.0" Onlin

Secure and fast microVMs for serverless computing.
Secure and fast microVMs for serverless computing.

Our mission is to enable secure, multi-tenant, minimal-overhead execution of container and function workloads. Read more about the Firecracker Charter

Scientific Computing Library in Rust

SciRust Scientific computing library written in Rust programming language. The objective is to design a generic library which can be used as a backbon

Owner
Bruce Yuan
Developer/Designer | Full-Stack Heavy-User of Rust/C/C++ and Python/JS/React
Bruce Yuan
Precio is a Rust library that implements the Precio protocol for computing private layered histograms and sums.

Overview of Precio Precio is a Rust implementation of the protocol described in eprint.iacr.org/2021/1490. The goal of the protocol is to enable an an

Microsoft 9 Aug 16, 2023
sodiumoxide clone, now with less chlorides and more oxides

sodiumoxide2 Less Chlorides, more Oxides! This package is a fork of sodiumoxide, using rust-native crypto. It's not intended to be easy to use or impl

Conrad Ludgate 3 Apr 16, 2023
An ownership model that is used to replace the Ring in Linux.

std-ownership An ownership model that is used to replace the Ring in Linux. It's 10x faster than Ring in Syscall. Overview The ownership system allows

Rhodes 4 Feb 13, 2023
Construct complex structures within single call + simple compile-time meta-inheritance model with mixins.

Introduction constructivism is a Rust sample-library designed to simplify the construction of structured data by defining and manipulating sequences o

polako.rs 5 Oct 24, 2023
Nyah is a programming language runtime built for high performance and comes with a scripting language.

?? Nyah ( Unfinished ) Nyah is a programming language runtime built for high performance and comes with a scripting language. ??️ Status Nyah is not c

Stacker 3 Mar 6, 2022
🐱 A high-speed JIT programming language and its runtime, meow~

?? A high-speed JIT programming language and its runtime, meow~

EnabledFish 30 Dec 22, 2022
Build database expression type checker and vectorized runtime executor in type-safe Rust

Typed Type Exercise in Rust Build database expression type checker and vectorized runtime executor in type-safe Rust. This project is highly inspired

Andy Lok 89 Dec 27, 2022
Secure mTLS and gRPC backed runtime daemon. Alternative to systemd. Written in Rust.

Auraed A runtime daemon written in Rust. Designed to run as pid 1 mTLS backed gRPC API over unix domain socket Run executables Run containers Run virt

Aurae Runtime 57 Dec 22, 2022
An efficient runtime for asynchronous applications in Rust.

PhotonIO PhotonIO is an efficient runtime for asynchronous applications in Rust. Features Asynchronous filesystem and networking I/O for Linux based o

PhotonDB 40 Jan 4, 2023
An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets.

Promise x Tokio = Prokio An asynchronous runtime compatible with WebAssembly and non-WebAssembly targets. Rationale When designing components and libr

Yew Stack 29 Feb 6, 2023