1use crate::primitive::Primitive;
2
3#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub enum Mutability {
5 Const,
6 Mut,
7}
8
9pub trait Reference<T: ?Sized>: Primitive + Sized {
10 #[must_use]
11 fn ref_type() -> Mutability;
12
13 #[must_use]
14 fn as_ref(&self) -> &Self;
15}
16
17macro_rules! impl_reference {
18 ($ref:tt, $ty:expr) => {
19 #[allow(unused_parens)]
20 impl<T: ?Sized> Primitive for $ref {}
21
22 #[allow(unused_parens)]
23 impl<T: ?Sized> Reference<T> for $ref {
24 fn ref_type() -> Mutability {
25 $ty
26 }
27
28 fn as_ref(&self) -> &Self {
29 self
30 }
31 }
32 };
33}
34
35impl_reference!((&T), Mutability::Const);
36impl_reference!((&mut T), Mutability::Mut);