1use std::{any, fmt, hash, marker::PhantomData};
6
7pub struct Typed<T, U> {
9 value: T,
11 _type: PhantomData<U>,
13}
14
15impl<T, U> Typed<T, U> {
16 pub(crate) fn new(value: T) -> Self {
18 Self {
19 value,
20 _type: PhantomData,
21 }
22 }
23
24 pub fn value(&self) -> &T {
26 &self.value
27 }
28
29 pub fn into_inner(self) -> T {
31 self.value
32 }
33}
34
35impl<T: AsRef<V>, U, V: ?Sized> AsRef<V> for Typed<T, U> {
36 fn as_ref(&self) -> &V {
37 self.value.as_ref()
38 }
39}
40
41impl<T: Clone, U> Clone for Typed<T, U> {
42 fn clone(&self) -> Self {
43 Self {
44 value: self.value.clone(),
45 _type: self._type,
46 }
47 }
48}
49
50impl<T: Copy, U> Copy for Typed<T, U> {}
51
52impl<T: fmt::Debug, U> fmt::Debug for Typed<T, U> {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 f.debug_tuple(any::type_name::<U>())
55 .field(&self.value)
56 .finish()
57 }
58}
59
60impl<T: fmt::Display, U> fmt::Display for Typed<T, U> {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 fmt::Display::fmt(&self.value, f)
63 }
64}
65
66impl<T: PartialEq, U> PartialEq for Typed<T, U> {
67 fn eq(&self, other: &Self) -> bool {
68 self.value == other.value
69 }
70}
71
72impl<T: Eq, U> Eq for Typed<T, U> {}
73
74impl<T: hash::Hash, U> hash::Hash for Typed<T, U> {
75 fn hash<H: hash::Hasher>(&self, state: &mut H) {
76 self.value.hash(state);
77 }
78}
79
80pub type Anchor<T> = Typed<u32, T>;