make-send-sync 0.1.0

Unsafely make any type Send and Sync
Documentation
  • Coverage
  • 100%
    31 out of 31 items documented1 out of 31 items with examples
  • Size
  • Source code size: 12.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.35 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Aseminaunz

Make Send Sync

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)) };