sendify

Crates.iosendify
lib.rssendify
version1.1.0
sourcesrc
created_at2020-05-24 08:26:08.617375
updated_at2020-05-24 09:12:55.335364
descriptionAn unsafe crate to wrap a reference to make it Send + Sync.
homepagehttps://github.com/rousan/sendify-rs
repositoryhttps://github.com/rousan/sendify-rs
max_upload_size
id245145
size12,647
Rousan Ali (rousan)

documentation

README

Github Actions Status crates.io Documentation MIT

sendify-rs

An unsafe crate to wrap a reference to make it Send + Sync to be able to transfer it between threads. Make sure the reference is still valid when unwrapping it.

Docs

Install

Add this to your Cargo.toml file:

[dependencies]
sendify = "1.1"

Example

use std::thread;

fn main() {
    let data = "my string".to_owned();

    let ref_val = &data;
    // Wrap the reference to make it Send + Sync.
    let sendify_val = sendify::wrap(ref_val);

    thread::spawn(move || {
        // Unwrap the reference, here make sure that reference is still valid otherwise
        // the app might crash.
        let ref_val = unsafe { sendify_val.unwrap() };
        assert_eq!(ref_val, "my string")
    })
    .join()
    .unwrap();

    assert_eq!(data, "my string")
}

Contributing

Your PRs and suggestions are always welcome.

Commit count: 13

cargo fmt