object_rainbow/
object_marker.rs1use std::fmt::Debug;
2
3use crate::*;
4
5#[derive(ToOutput, InlineOutput, ListHashes, Topological, Parse, ParseInline)]
6pub struct ObjectMarker<T: ?Sized> {
7 object: PhantomData<fn() -> T>,
8}
9
10impl<T: ?Sized> Clone for ObjectMarker<T> {
11 fn clone(&self) -> Self {
12 *self
13 }
14}
15
16impl<T: ?Sized> Copy for ObjectMarker<T> {}
17
18impl<T: ?Sized> Default for ObjectMarker<T> {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24impl<T: ?Sized> ObjectMarker<T> {
25 pub const fn new() -> Self {
26 Self {
27 object: PhantomData,
28 }
29 }
30}
31
32impl<T: ?Sized + Tagged> Tagged for ObjectMarker<T> {
33 const TAGS: Tags = T::TAGS;
34 const HASH: Hash = T::HASH;
35}
36
37impl<T: ?Sized> PartialEq for ObjectMarker<T> {
38 fn eq(&self, other: &Self) -> bool {
39 self.object == other.object
40 }
41}
42
43impl<T: ?Sized> Eq for ObjectMarker<T> {}
44
45impl<T: ?Sized> PartialOrd for ObjectMarker<T> {
46 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
47 Some(self.cmp(other))
48 }
49}
50
51impl<T: ?Sized> Ord for ObjectMarker<T> {
52 fn cmp(&self, other: &Self) -> Ordering {
53 self.object.cmp(&other.object)
54 }
55}
56
57impl<T: ?Sized> core::hash::Hash for ObjectMarker<T> {
58 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
59 self.object.hash(state);
60 }
61}
62
63impl<T: ?Sized> Debug for ObjectMarker<T> {
64 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 f.debug_struct("ObjectMarker")
66 .field("object", &self.object)
67 .finish()
68 }
69}
70
71impl<T: ?Sized> Size for ObjectMarker<T> {
72 type Size = typenum::U0;
73 const SIZE: usize = 0;
74}
75
76impl<T: ?Sized> MaybeHasNiche for ObjectMarker<T> {
77 type MnArray = NoNiche<ZeroNoNiche<<Self as Size>::Size>>;
78}