extern crate alloc;
use core::{clone, convert, marker, mem, ops, pin};
pub trait Lock<T: ?Sized>: marker::Send + marker::Sync {
type Guard<'a>: ops::Deref<Target = T> + ops::DerefMut
where
Self: 'a;
fn lock(&self) -> Self::Guard<'_>;
}
pub trait ConstructibleLock<T>: Lock<T> + convert::From<T> {
fn get_mut(&mut self) -> &mut T;
}
pub struct LockForInner<'a, OT, OL, TAG>
where
OT: 'a + ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
lock_for_outer: &'a OL,
_phantom: marker::PhantomData<fn() -> (*const OT, *const TAG)>,
}
impl<'a, OT, OL, TAG> LockForInner<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
pub fn from_outer(lock_for_outer: &'a OL) -> Self {
Self {
lock_for_outer,
_phantom: marker::PhantomData,
}
}
}
impl<'a, OT, OL, TAG> Lock<<OT as DerefInnerByTag<TAG>>::Output> for LockForInner<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
type Guard<'b>
= LockForInnerGuard<'b, OT, OL, TAG>
where
Self: 'b;
fn lock(&self) -> Self::Guard<'_> {
let guard_for_outer = self.lock_for_outer.lock();
LockForInnerGuard {
guard_for_outer,
_phantom_tag: marker::PhantomData,
}
}
}
pub struct LockForInnerGuard<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
guard_for_outer: OL::Guard<'a>,
_phantom_tag: marker::PhantomData<fn() -> *const TAG>,
}
impl<'a, OT, OL, TAG> LockForInnerGuard<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
pub fn from_outer(guard_for_outer: OL::Guard<'a>) -> Self {
Self {
guard_for_outer,
_phantom_tag: marker::PhantomData,
}
}
pub fn into_outer(self) -> OL::Guard<'a> {
self.guard_for_outer
}
}
impl<'a, OT, OL, TAG> ops::Deref for LockForInnerGuard<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
type Target = <OT as DerefInnerByTag<TAG>>::Output;
fn deref(&self) -> &Self::Target {
<OT as DerefInnerByTag<TAG>>::deref_inner(self.guard_for_outer.deref())
}
}
impl<'a, OT, OL, TAG> ops::DerefMut for LockForInnerGuard<'a, OT, OL, TAG>
where
OT: ?Sized + DerefMutInnerByTag<TAG>,
OL: 'a + Lock<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send,
{
fn deref_mut(&mut self) -> &mut Self::Target {
<OT as DerefMutInnerByTag<TAG>>::deref_mut_inner(self.guard_for_outer.deref_mut())
}
}
pub trait RwLock<T>: marker::Send + marker::Sync + convert::From<T> {
type ReadGuard<'a>: ops::Deref<Target = T>
where
Self: 'a;
type WriteGuard<'a>: ops::Deref<Target = T> + ops::DerefMut
where
Self: 'a;
fn read(&self) -> Self::ReadGuard<'_>;
fn write(&self) -> Self::WriteGuard<'_>;
fn get_mut(&mut self) -> &mut T;
}
pub trait SyncRcPtr<T: ?Sized>: Clone + ops::Deref<Target = T> + marker::Send + marker::Sync + marker::Unpin {
type WeakSyncRcPtr: WeakSyncRcPtr<T, Self>;
type SyncRcPtrRef<'a>: SyncRcPtrRef<'a, T, Self>
where
Self: 'a;
fn downgrade(&self) -> Self::WeakSyncRcPtr;
fn as_ref(&self) -> Self::SyncRcPtrRef<'_> {
Self::SyncRcPtrRef::new(self)
}
fn into_raw(this: Self) -> *const T;
unsafe fn from_raw(ptr: *const T) -> Self;
}
pub trait WeakSyncRcPtr<T: ?Sized, P: SyncRcPtr<T>>: Clone + marker::Send + marker::Unpin {
fn upgrade(&self) -> Option<P>;
fn into_raw(this: Self) -> *const T;
unsafe fn from_raw(ptr: *const T) -> Self;
}
#[derive(Debug)]
pub enum SyncRcPtrTryNewError {
AllocationFailure,
}
#[derive(Debug)]
pub enum SyncRcPtrTryNewWithError<E> {
TryNewError(SyncRcPtrTryNewError),
WithError(E),
}
pub trait SyncRcPtrFactory {
type SyncRcPtr<T>: SyncRcPtr<T>
where
T: marker::Send + marker::Sync;
fn try_new<T>(value: T) -> Result<Self::SyncRcPtr<T>, SyncRcPtrTryNewError>
where
T: marker::Send + marker::Sync;
fn try_new_recoverable<T>(value: T) -> Result<Self::SyncRcPtr<T>, (T, SyncRcPtrTryNewError)>
where
T: marker::Send + marker::Sync,
{
let uninit = match Self::try_new::<mem::MaybeUninit<T>>(mem::MaybeUninit::uninit()) {
Ok(uninit) => uninit,
Err(e) => return Err((value, e)),
};
let p: *const mem::MaybeUninit<T> = SyncRcPtr::into_raw(uninit);
let p = p as *mut mem::MaybeUninit<T>;
unsafe { &mut *p }.write(value);
let p = p as *const T;
let p = unsafe { Self::SyncRcPtr::<T>::from_raw(p) };
Ok(p)
}
fn try_new_with<T, R, E, N>(new: N) -> Result<(Self::SyncRcPtr<T>, R), SyncRcPtrTryNewWithError<E>>
where
T: marker::Send + marker::Sync,
N: ops::FnOnce() -> Result<(T, R), E>,
{
let uninit = match Self::try_new::<mem::MaybeUninit<T>>(mem::MaybeUninit::uninit()) {
Ok(uninit) => uninit,
Err(e) => return Err(SyncRcPtrTryNewWithError::TryNewError(e)),
};
let (value, new_res) = match new() {
Ok(r) => r,
Err(e) => return Err(SyncRcPtrTryNewWithError::WithError(e)),
};
let p: *const mem::MaybeUninit<T> = SyncRcPtr::into_raw(uninit);
let p = p as *mut mem::MaybeUninit<T>;
unsafe { &mut *p }.write(value);
let p = p as *const T;
let p = unsafe { Self::SyncRcPtr::<T>::from_raw(p) };
Ok((p, new_res))
}
}
pub trait SyncRcPtrRef<'a, T: ?Sized, P: 'a + SyncRcPtr<T>>: Clone + ops::Deref<Target = T> {
fn new(p: &'a P) -> Self;
fn make_clone(&self) -> P;
fn make_weak_clone(&self) -> P::WeakSyncRcPtr;
}
pub struct PinnedWeakSyncRcPtr<T: ?Sized, P: SyncRcPtr<T>> {
weak_ptr: P::WeakSyncRcPtr,
}
impl<T: ?Sized, P: SyncRcPtr<T>> PinnedWeakSyncRcPtr<T, P> {
fn downgrade<'a, R: SyncRcPtrRef<'a, T, P>>(ptr_ref: &pin::Pin<R>) -> Self
where
P: 'a,
{
let ptr_ref = unsafe { pin::Pin::into_inner_unchecked(ptr_ref.clone()) };
Self {
weak_ptr: ptr_ref.make_weak_clone(),
}
}
}
impl<T: ?Sized, P: SyncRcPtr<T>> Clone for PinnedWeakSyncRcPtr<T, P> {
fn clone(&self) -> Self {
Self {
weak_ptr: self.weak_ptr.clone(),
}
}
}
impl<T: ?Sized, P: SyncRcPtr<T>> WeakSyncRcPtr<T, pin::Pin<P>> for PinnedWeakSyncRcPtr<T, P> {
fn upgrade(&self) -> Option<pin::Pin<P>> {
self.weak_ptr.upgrade().map(|ptr| {
unsafe { pin::Pin::new_unchecked(ptr) }
})
}
fn into_raw(this: Self) -> *const T {
P::WeakSyncRcPtr::into_raw(this.weak_ptr)
}
unsafe fn from_raw(ptr: *const T) -> Self {
let weak_ptr = unsafe { P::WeakSyncRcPtr::from_raw(ptr) };
Self { weak_ptr }
}
}
impl<T: ?Sized, P: SyncRcPtr<T>> SyncRcPtr<T> for pin::Pin<P> {
type SyncRcPtrRef<'a>
= pin::Pin<P::SyncRcPtrRef<'a>>
where
P: 'a;
type WeakSyncRcPtr = PinnedWeakSyncRcPtr<T, P>;
fn downgrade(&self) -> Self::WeakSyncRcPtr {
PinnedWeakSyncRcPtr::downgrade(&<Self as SyncRcPtr<T>>::as_ref(self))
}
fn as_ref(&self) -> Self::SyncRcPtrRef<'_> {
<Self::SyncRcPtrRef<'_> as SyncRcPtrRef<'_, T, Self>>::new(self)
}
fn into_raw(this: Self) -> *const T {
let this = unsafe { pin::Pin::into_inner_unchecked(this) };
P::into_raw(this)
}
unsafe fn from_raw(ptr: *const T) -> Self {
unsafe {
let p = P::from_raw(ptr);
pin::Pin::new_unchecked(p)
}
}
}
impl<'a, T: ?Sized, P: SyncRcPtr<T>, R: SyncRcPtrRef<'a, T, P>> SyncRcPtrRef<'a, T, pin::Pin<P>> for pin::Pin<R>
where
P: 'a,
{
fn new(p: &'a pin::Pin<P>) -> Self {
let p = p as *const pin::Pin<P> as *const P;
let p: &'a P = unsafe { &*p };
let r = R::new(p);
unsafe { pin::Pin::new_unchecked(r) }
}
fn make_clone(&self) -> pin::Pin<P> {
unsafe { pin::Pin::new_unchecked(pin::Pin::into_inner_unchecked(self.clone()).make_clone()) }
}
fn make_weak_clone(&self) -> <pin::Pin<P> as SyncRcPtr<T>>::WeakSyncRcPtr {
PinnedWeakSyncRcPtr::downgrade(self)
}
}
pub struct GenericSyncRcPtrRef<'a, T: ?Sized, P: SyncRcPtr<T>> {
r: &'a P,
_phantom: marker::PhantomData<fn() -> *const T>,
}
impl<'a, T: ?Sized, P: SyncRcPtr<T>> Clone for GenericSyncRcPtrRef<'a, T, P> {
fn clone(&self) -> Self {
Self {
r: self.r,
_phantom: marker::PhantomData,
}
}
}
impl<'a, T: ?Sized, P: SyncRcPtr<T>> ops::Deref for GenericSyncRcPtrRef<'a, T, P> {
type Target = T;
fn deref(&self) -> &Self::Target {
self.r.deref()
}
}
impl<'a, T: ?Sized, P: SyncRcPtr<T>> SyncRcPtrRef<'a, T, P> for GenericSyncRcPtrRef<'a, T, P> {
fn new(p: &'a P) -> Self {
Self {
r: p,
_phantom: marker::PhantomData,
}
}
fn make_clone(&self) -> P {
self.r.clone()
}
fn make_weak_clone(&self) -> P::WeakSyncRcPtr {
self.r.downgrade()
}
}
pub trait DerefInnerByTag<TAG> {
type Output: ?Sized;
fn deref_inner(&self) -> &Self::Output;
fn to_inner_ptr(outer: *const Self) -> *const Self::Output;
unsafe fn container_of(inner: *const Self::Output) -> *const Self;
}
#[macro_export]
macro_rules! impl_deref_inner_by_tag {
($field:ident, $field_type:ty) => {
type Output = $field_type;
fn deref_inner(&self) -> &Self::Output {
&self.$field
}
#[allow(clippy::not_unsafe_ptr_arg_deref)]
fn to_inner_ptr(outer: *const Self) -> *const Self::Output {
use core::ptr;
unsafe { ptr::addr_of!((*outer).$field) }
}
unsafe fn container_of(inner: *const Self::Output) -> *const Self {
use core::mem;
unsafe {
inner
.cast::<u8>()
.sub(mem::offset_of!(Self, $field))
.cast::<Self>()
}
}
};
}
pub trait DerefMutInnerByTag<TAG>: DerefInnerByTag<TAG> {
fn deref_mut_inner(&mut self) -> &mut Self::Output;
}
#[macro_export]
macro_rules! impl_deref_mut_inner_by_tag {
($field:ident) => {
fn deref_mut_inner(&mut self) -> &mut Self::Output {
&mut self.$field
}
};
}
pub struct SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
ptr_to_outer: OP,
_phantom: marker::PhantomData<fn() -> (*const OT, *const TAG)>,
}
impl<OT, OP, TAG> SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
pub fn new(ptr_to_outer: OP) -> Self {
Self {
ptr_to_outer,
_phantom: marker::PhantomData,
}
}
pub fn get_container(&self) -> OP::SyncRcPtrRef<'_> {
self.ptr_to_outer.as_ref()
}
pub fn into_container(self) -> OP {
self.ptr_to_outer
}
}
impl<OT, OP, TAG> SyncRcPtrForInner<OT, pin::Pin<OP>, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
pub unsafe fn new_projection_pin(ptr_to_outer: pin::Pin<OP>) -> pin::Pin<Self> {
unsafe {
pin::Pin::new_unchecked(Self {
ptr_to_outer,
_phantom: marker::PhantomData,
})
}
}
}
impl<OT, OP, TAG> convert::From<OP> for SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
fn from(value: OP) -> Self {
Self::new(value)
}
}
impl<OT, OP, TAG> clone::Clone for SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
fn clone(&self) -> Self {
Self {
ptr_to_outer: self.ptr_to_outer.clone(),
_phantom: marker::PhantomData,
}
}
}
impl<OT, OP, TAG> ops::Deref for SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
type Target = <OT as DerefInnerByTag<TAG>>::Output;
fn deref(&self) -> &Self::Target {
DerefInnerByTag::<TAG>::deref_inner(self.ptr_to_outer.deref())
}
}
impl<OT, OP, TAG> marker::Unpin for SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
}
impl<OT, OP, TAG> SyncRcPtr<<OT as DerefInnerByTag<TAG>>::Output> for SyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
type WeakSyncRcPtr = WeakSyncRcPtrForInner<OT, OP, TAG>;
type SyncRcPtrRef<'a>
= SyncRcPtrRefForInner<'a, OT, OP, OP::SyncRcPtrRef<'a>, TAG>
where
OP: 'a,
OT: 'a,
TAG: 'a;
fn downgrade(&self) -> Self::WeakSyncRcPtr {
WeakSyncRcPtrForInner {
weak_ptr_to_outer: self.ptr_to_outer.downgrade(),
_phantom: marker::PhantomData,
}
}
fn into_raw(this: Self) -> *const <OT as DerefInnerByTag<TAG>>::Output {
let outer = OP::into_raw(this.ptr_to_outer);
<OT as DerefInnerByTag<TAG>>::to_inner_ptr(outer)
}
unsafe fn from_raw(ptr: *const <OT as DerefInnerByTag<TAG>>::Output) -> Self {
let ptr_to_outer = unsafe { <OT as DerefInnerByTag<TAG>>::container_of(ptr) };
let ptr_to_outer = unsafe { OP::from_raw(ptr_to_outer) };
Self {
ptr_to_outer,
_phantom: marker::PhantomData,
}
}
}
pub struct WeakSyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
weak_ptr_to_outer: OP::WeakSyncRcPtr,
_phantom: marker::PhantomData<fn() -> (*const OT, *const TAG)>,
}
impl<OT, OP, TAG> clone::Clone for WeakSyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
fn clone(&self) -> Self {
Self {
weak_ptr_to_outer: self.weak_ptr_to_outer.clone(),
_phantom: marker::PhantomData,
}
}
}
impl<OT, OP, TAG> marker::Unpin for WeakSyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
}
impl<OT, OP, TAG> WeakSyncRcPtr<<OT as DerefInnerByTag<TAG>>::Output, SyncRcPtrForInner<OT, OP, TAG>>
for WeakSyncRcPtrForInner<OT, OP, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
fn upgrade(&self) -> Option<SyncRcPtrForInner<OT, OP, TAG>> {
self.weak_ptr_to_outer
.upgrade()
.map(|ptr_to_outer| SyncRcPtrForInner::<OT, OP, TAG> {
ptr_to_outer,
_phantom: marker::PhantomData,
})
}
fn into_raw(this: Self) -> *const <OT as DerefInnerByTag<TAG>>::Output {
let outer = OP::WeakSyncRcPtr::into_raw(this.weak_ptr_to_outer);
<OT as DerefInnerByTag<TAG>>::to_inner_ptr(outer)
}
unsafe fn from_raw(ptr: *const <OT as DerefInnerByTag<TAG>>::Output) -> Self {
let ptr_to_outer = unsafe { <OT as DerefInnerByTag<TAG>>::container_of(ptr) };
let weak_ptr_to_outer = unsafe { OP::WeakSyncRcPtr::from_raw(ptr_to_outer) };
Self {
weak_ptr_to_outer,
_phantom: marker::PhantomData,
}
}
}
pub struct SyncRcPtrRefForInner<'a, OT, OP, OR, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: 'a + SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, OP>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
TAG: 'a,
{
ptr_to_outer_ref: OR,
#[allow(clippy::type_complexity)]
_phantom: marker::PhantomData<fn() -> (&'a (), *const OT, *const OP, *const TAG)>,
}
impl<'a, OT, OP, OR, TAG> SyncRcPtrRefForInner<'a, OT, OP, OR, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: 'a + SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, OP>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
TAG: 'a,
{
pub fn new(ptr_to_outer_ref: &OR) -> Self {
Self {
ptr_to_outer_ref: ptr_to_outer_ref.clone(),
_phantom: marker::PhantomData,
}
}
pub fn get_container(&self) -> &OR {
&self.ptr_to_outer_ref
}
}
impl<'a, OT, OP, OR, TAG> SyncRcPtrRefForInner<'a, OT, pin::Pin<OP>, OR, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, pin::Pin<OP>>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
{
pub unsafe fn new_projection_pin(ptr_to_outer_ref: &OR) -> pin::Pin<Self> {
unsafe {
pin::Pin::new_unchecked(Self {
ptr_to_outer_ref: ptr_to_outer_ref.clone(),
_phantom: marker::PhantomData,
})
}
}
}
impl<'a, OT, OP, OR, TAG> Clone for SyncRcPtrRefForInner<'a, OT, OP, OR, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: 'a + SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, OP>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
TAG: 'a,
{
fn clone(&self) -> Self {
Self {
ptr_to_outer_ref: self.ptr_to_outer_ref.clone(),
_phantom: marker::PhantomData,
}
}
}
impl<'a, OT, OP, OR, TAG> ops::Deref for SyncRcPtrRefForInner<'a, OT, OP, OR, TAG>
where
OT: ?Sized + DerefInnerByTag<TAG>,
OP: 'a + SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, OP>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
TAG: 'a,
{
type Target = <OT as DerefInnerByTag<TAG>>::Output;
fn deref(&self) -> &Self::Target {
DerefInnerByTag::<TAG>::deref_inner(self.ptr_to_outer_ref.deref())
}
}
impl<'a, OT, OP, OR, TAG> SyncRcPtrRef<'a, <OT as DerefInnerByTag<TAG>>::Output, SyncRcPtrForInner<OT, OP, TAG>>
for SyncRcPtrRefForInner<'a, OT, OP, OR, TAG>
where
OT: 'a + ?Sized + DerefInnerByTag<TAG>,
OP: 'a + SyncRcPtr<OT>,
OR: SyncRcPtrRef<'a, OT, OP>,
<OT as DerefInnerByTag<TAG>>::Output: marker::Send + marker::Sync,
TAG: 'a,
{
fn new(p: &'a SyncRcPtrForInner<OT, OP, TAG>) -> Self {
Self::new(&OR::new(&p.ptr_to_outer))
}
fn make_clone(&self) -> SyncRcPtrForInner<OT, OP, TAG> {
SyncRcPtrForInner::<OT, OP, TAG> {
ptr_to_outer: self.ptr_to_outer_ref.make_clone(),
_phantom: marker::PhantomData,
}
}
fn make_weak_clone(
&self,
) -> <SyncRcPtrForInner<OT, OP, TAG> as SyncRcPtr<<OT as DerefInnerByTag<TAG>>::Output>>::WeakSyncRcPtr {
WeakSyncRcPtrForInner::<OT, OP, TAG> {
weak_ptr_to_outer: self.ptr_to_outer_ref.make_weak_clone(),
_phantom: marker::PhantomData,
}
}
}
pub trait SyncTypes: marker::Unpin + 'static {
type Lock<T: marker::Send>: ConstructibleLock<T>;
type RwLock<T: marker::Send + marker::Sync>: RwLock<T>;
type SyncRcPtrFactory: SyncRcPtrFactory;
}
mod generic_arc;
pub use generic_arc::{GenericArc, GenericArcFactory, GenericWeak};