refcapsule

Crates.iorefcapsule
lib.rsrefcapsule
version0.1.0-beta1
sourcesrc
created_at2022-11-07 07:57:52.714253
updated_at2022-11-07 07:57:52.714253
descriptionSafely send references to other threads
homepage
repositoryhttps://gitlab.com/thayne/refcapsule
max_upload_size
id707084
size27,421
Thayne McCombs (tmccombs)

documentation

README

refcapsule

Safely send references to other threads in rust

A way to create a scope in which you can send references across a channel

Example:

use std::thread;
use std::time::Duration;
use std::sync::mpsc::channel;
use refcapsule::{Capsule, with_encapsulated};

let (sender, receiver) = channel::<Capsule<u32>>();

// receiver of references

thread::spawn(move || {
    {
        let r = receiver.recv().unwrap();
        thread::sleep(Duration::from_millis(100));
        assert_eq!(*r, 4);
    }
    {
        let r = receiver.recv().unwrap();
        thread::sleep(Duration::from_millis(100));
        assert_eq!(*r, 12);
    }
});

let x: u32 = 4;
let s1 = sender.clone();
with_encapsulated(&x, move |x| s1.send(x).unwrap());

with_encapsulated(&12, move |cap| sender.send(cap).unwrap());
Commit count: 13

cargo fmt