sendptr 0.1.2

Convenient cross-thread raw pointer usage / 方便跨线程用裸指针
Documentation
#![cfg_attr(docsrs, feature(doc_cfg))]

use std::ops::Deref;

#[derive(Clone)]
pub struct SendPtr<T>(*const T);

unsafe impl<T> Send for SendPtr<T> {}
unsafe impl<T> Sync for SendPtr<T> {}

impl<T> SendPtr<T> {
  pub fn new(ptr: *const T) -> Self {
    SendPtr(ptr)
  }

  pub fn get(&self) -> *const T {
    self.0
  }
}

impl<T> Deref for SendPtr<T> {
  type Target = T;
  fn deref(&self) -> &Self::Target {
    unsafe { &*self.0 }
  }
}