dungeon_cell/bound/
equal.rs

1use crate::marker_traits::IsBound;
2
3use super::{traits, Bound};
4
5/// Check if dynamic trait bound is the same as another dynamic trait bound.
6///
7/// This trait is [sealed](https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed)
8/// and cannot be implemented outside of the implementations here.
9///
10/// # Examples
11/// ```
12/// use dungeon_cell::bound::{Equal, bounds};
13/// use dungeon_cell::marker_traits::IsBound;
14///
15/// fn test<A: Equal<B> + IsBound, B: IsBound>() {}
16///
17/// test::<bounds::Empty, bounds::Empty>();
18/// test::<bounds::Send, bounds::Send>();
19/// test::<bounds::Normal, bounds::Normal>();
20/// ```
21/// ```compile_fail
22/// use dungeon_cell::bound::{Equal, bounds};
23/// use dungeon_cell::marker_traits::IsBound;
24///
25/// fn test<A: Equal<B> + IsBound, B: IsBound>() {}
26///
27/// test::<bounds::Copy, bounds::Empty>();
28/// ```
29pub trait Equal<T: IsBound>: IsBound {}
30
31impl<
32        SendB,
33        SyncB,
34        CopyB,
35        CloneB,
36        UnpinB,
37        DebugB,
38        SendA,
39        SyncA,
40        CopyA,
41        CloneA,
42        UnpinA,
43        DebugA,
44    > Equal<Bound<SendB, SyncB, CopyB, CloneB, UnpinB, DebugB>>
45    for Bound<SendA, SyncA, CopyA, CloneA, UnpinA, DebugA>
46where
47    Bound<SendB, SyncB, CopyB, CloneB, UnpinB, DebugB>: IsBound,
48    Bound<SendA, SyncA, CopyA, CloneA, UnpinA, DebugA>: IsBound,
49    SendA: EqualHelper<SendB>,
50    SyncA: EqualHelper<SyncB>,
51    CopyA: EqualHelper<CopyB>,
52    CloneA: EqualHelper<CloneB>,
53    UnpinA: EqualHelper<UnpinB>,
54    DebugA: EqualHelper<DebugB>,
55{
56}
57
58pub trait EqualHelper<T> {}
59
60impl EqualHelper<traits::__> for traits::__ {}
61impl EqualHelper<traits::Send> for traits::Send {}
62impl EqualHelper<traits::Sync> for traits::Sync {}
63impl EqualHelper<traits::Copy> for traits::Copy {}
64impl EqualHelper<traits::Clone> for traits::Clone {}
65impl EqualHelper<traits::Unpin> for traits::Unpin {}
66impl EqualHelper<traits::Debug> for traits::Debug {}