Skip to main content

Crate make_send_sync

Crate make_send_sync 

Source
Expand description

crates.io docs.rs license repository no-std

Wrapper types to unsafely make any type Send and/or Sync.

use ::core::{
	cell::UnsafeCell,
	ptr,
};
use ::make_send_sync::{
	UnsafeSendSync,
	UnsafeSync,
};

// A type that is not Send or Sync
let not_thread_safe: *const u8 = ptr::dangling();

let wrapped: UnsafeSendSync<*const u8> = unsafe { UnsafeSendSync::new(not_thread_safe) };

fn assert_send_sync<T: Send + Sync>(_: T) {}

// `wrapper` is Send + Sync, even though `not_thread_safe` is not.
assert_send_sync(wrapped);

// Look! SyncUnsafeCell on stable!
static MY_CELL: UnsafeSync<UnsafeCell<u8>> = unsafe { UnsafeSync::new(UnsafeCell::new(0)) };

Structsยง

UnsafeSend
A wrapper that unsafely makes T Send without requiring it for T.
UnsafeSendSync
A wrapper that unsafely makes T Send + Sync without requiring it for T.
UnsafeSync
A wrapper that unsafely makes T Sync without requiring it for T.