https://github.com/rousan/sendify-rs
An unsafe crate to wrap a reference to make it Send + Sync to be able to transfer it between threads
https://github.com/rousan/sendify-rs
reference rust send sync unsafe
Last synced: 9 months ago
JSON representation
An unsafe crate to wrap a reference to make it Send + Sync to be able to transfer it between threads
- Host: GitHub
- URL: https://github.com/rousan/sendify-rs
- Owner: rousan
- License: mit
- Created: 2020-05-23T23:55:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-24T09:12:21.000Z (about 6 years ago)
- Last Synced: 2025-06-09T12:11:54.244Z (about 1 year ago)
- Topics: reference, rust, send, sync, unsafe
- Language: Rust
- Homepage:
- Size: 22.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/rousan/sendify-rs/actions)
[](https://crates.io/crates/sendify)
[](https://docs.rs/sendify)
[](./LICENSE)
# sendify-rs
An unsafe crate to wrap a reference to make it [`Send`](https://doc.rust-lang.org/nightly/core/marker/trait.Send.html) + [`Sync`](https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html) to be able to transfer it between threads. Make sure the reference is still valid when unwrapping it.
[Docs](https://docs.rs/sendify)
## Install
Add this to your `Cargo.toml` file:
```toml
[dependencies]
sendify = "1.1"
```
## Example
```rust
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.