dungeon_cell/bound/
disjoint.rs

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