1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*!
Zero-sized types .
*/

use std::{cell::Cell,marker::PhantomData, rc::Rc};

use crate::{
    derive_macro_reexports::*,
    type_layout::{
        MonoTypeLayout, MonoTLData, ReprAttr, TypeLayout, GenericTLData,
    }
};



/// Marker type used to mark a type as being Send+Sync.
#[repr(C)]
#[derive(StableAbi)]
pub struct SyncSend;

/// Marker type used to mark a type as being !Send+!Sync.
#[repr(C)]
#[derive(StableAbi)]
pub struct UnsyncUnsend {
    _marker: UnsafeIgnoredType<Rc<()>>,
}

/// Marker type used to mark a type as being Send+!Sync.
#[repr(C)]
#[derive(StableAbi)]
pub struct UnsyncSend {
    _marker: UnsafeIgnoredType<Cell<()>>,
}


/// Marker type used to mark a type as being !Send+Sync.
#[repr(C)]
#[derive(StableAbi)]
pub struct SyncUnsend {
    _marker: UnsyncUnsend,
}

unsafe impl Sync for SyncUnsend{}


/// Zero-sized marker type used to signal that even though a type 
/// could implement Copy and Clone,
/// it is semantically an error to do so.
#[repr(C)]
#[derive(StableAbi)]
pub struct NotCopyNotClone;



/// Used by vtables/pointers to signal that the type has been erased.
///
#[repr(C)]
#[derive(StableAbi)]
pub struct ErasedObject<T=()>{
    _priv: [u8; 0],
    _marker:PhantomData<extern "C" fn()->T>,
}


/**
MarkerType which ignores its type parameter in its StableAbi implementation.

# Safety

`Unsafe` is part of its name,
because users could inadvertently violate memory safety
if they depend on the value of the type parameter passed to `UnsafeIgnoredType` for safety,
since the other side could choose any other type parameter.

*/
#[repr(C)]
pub struct UnsafeIgnoredType<T:?Sized> {
    _priv: [u8; 0],
    _inner: PhantomData<T>,
}

impl<T:?Sized> UnsafeIgnoredType<T>{
    pub const DEFAULT:Self=Self{
        _priv:[],
        _inner:PhantomData,
    };

    pub const NEW:Self=Self{
        _priv:[],
        _inner:PhantomData,
    };
}

impl<T:?Sized> Copy for UnsafeIgnoredType<T>{}

impl<T:?Sized> Default for UnsafeIgnoredType<T>{
    fn default()->Self{
        Self::DEFAULT
    }
}

impl<T:?Sized> Clone for UnsafeIgnoredType<T>{
    fn clone(&self)->Self{
        *self
    }
}



unsafe impl<T> GetStaticEquivalent_ for UnsafeIgnoredType<T> {
    type StaticEquivalent=();
}
unsafe impl<T> SharedStableAbi for UnsafeIgnoredType<T> {
    type IsNonZeroType = False;
    type Kind=ValueKind;


    const S_LAYOUT: &'static TypeLayout = {
        const MONO_TYPE_LAYOUT:&'static MonoTypeLayout=&MonoTypeLayout::new(
            *mono_shared_vars,
            rstr!("UnsafeIgnoredType"),
            make_item_info!(),
            MonoTLData::struct_(rslice![]),
            tl_genparams!(;;),
            ReprAttr::C,
            ModReflMode::Module,
            rslice![],
        );

        make_shared_vars!{
            let (mono_shared_vars,shared_vars)={};
        }

        &TypeLayout::from_std::<Self>(
            shared_vars,
            MONO_TYPE_LAYOUT,
            Self::S_ABI_CONSTS,
            GenericTLData::Struct,
        )
    };
}