fairjax_core 0.1.0

Core package for fairjax
Documentation
  • Coverage
  • 29.17%
    28 out of 96 items documented0 out of 76 items with examples
  • Size
  • Source code size: 39.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.43 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Emilostuff/fairjax
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Emilostuff

Fairjax

A Rust crate for efficiently performing fair join pattern matching i.e. the process of matching several received messages in a mailbox against one of more patterns. If we can find a combination of messages that matches a pattern and satisfies the guard, the messages are consumed and the body of the match arm is executed.

Fair and Deterministic Matching

fairjax implements join pattern matching in a fair and deterministic manner, ensuring that we always match the oldest messages possible. Furthermore this ensures completely deterministic and reproducible behavior.

Example

// Define message types
pub enum Msg {
    A(usize, f64),
    B(usize, f64),
}

use Msg::*;

// Declare state-keeping mailbox
let mut mailbox = fairjax_core::MailBox::default();

// Simulate input messages
let messages = vec![
    A(0, 1.4),
    B(0, 1.8),
    B(1, 5.2),
    A(2, 42.1),
    A(1, 5.9),
    B(2, 42.5)
];

let mut matches = vec![];

// Recieve message one by one
for msg in messages {
    // Declare join pattern matching
    fairjax::fairjax!(match msg >> [mailbox, Msg] {
       (A(id, ts1), B(id, ts2)) if ts1 < ts2 => {
           matches.push(id);
       }
    });
}

assert_eq!(vec![0, 2], matches);