ration

Crates.ioration
lib.rsration
version0.2.1
created_at2025-02-11 15:13:42.011203+00
updated_at2025-03-12 17:47:02.930105+00
descriptionA shared memory library
homepagehttps://github.com/rtthw/ration
repositoryhttps://github.com/rtthw/ration
max_upload_size
id1551531
size37,144
Matthew Norman (rtthw)

documentation

README

Ration

A shared memory library for Rust. Useful for interprocess communication (IPC) through message-passing, sharing data structures, etc.

Features

  • Performance.

    Shared memory is as fast as you can get when it comes to interprocess communication.

  • Flexibility.

    Simple data structures that can be used in a variety of ways. Abstract and combine them however you like to form your own types.

Quickstart

In your main process (the one that owns the shared allocation), create your shared type and give it some initial data (don't forget this part because blocks don't start off with initial data, and accessing unitialized data is undefined behavior):

use ration::Block;

fn main() {
    let mut block: Block<i32> = Block::alloc("/tmp/MY_BLOCK").unwrap();
    *block = 71;
}

...then in some other process, you can access (and even mutate it) like so:

use ration::Block;

fn main() {
    let mut block: Block<i32> = Block::open("/tmp/MY_BLOCK").unwrap();
    println!("MY_BLOCK VALUE: {:?}", *block); // 71
}

[!NOTE] I'd recommend using some mutable access checker (like a Mutex) if you plan on mutating shared data.

Examples

  • The obligatory "Hello, world!" program that passes a single character string from server to client.

    Server and client.

  • A simple channel type that passes messages between server and client.

    Server and client.

  • A FizzBuzz clone that uses the Block type as a singleton. Also shows how to share strings.

    Link.

License

MIT

Commit count: 46

cargo fmt