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
#![cfg_attr(rustfmt, rustfmt::skip)]

use super::*;

#[derive_ReprC(dyn)]
pub
trait DropGlue {}

/// We need to use a new type to avoid the trait-coherence issues of
/// an otherwise too blanket-y impl.
#[derive(Debug)]
#[repr(transparent)]
pub
struct ImplDropGlue<T>(pub T);

impl<T> DropGlue for ImplDropGlue<T> {}

impl DynDrop {
    pub
    fn new (value: impl 'static + Send + Sync)
      -> DynDrop
    {
        Self(::std::sync::Arc::new(ImplDropGlue(value)).into())
    }
}

/// Convenience shorthand around
/// `VirtualPtr<dyn 'static + Send + Sync + DropGlue>`.
#[derive(Debug, Clone)]
#[derive_ReprC]
#[repr(transparent)]
pub
struct DynDrop /* = */ (
    pub VirtualPtr<dyn 'static + Send + Sync + StaticDropGlue>,
);

#[derive_ReprC(dyn, Clone)]
pub
trait StaticDropGlue : Send + Sync {}

impl<T> StaticDropGlue for ImplDropGlue<T>
where
    T : 'static + Send + Sync,
{}