1use crate::{MovableRef, Ref};
4
5pub trait SectionItemLocation<T: ?Sized> {
7 fn item_ptr(&self) -> *const T;
9}
10
11impl<T: ?Sized> SectionItemLocation<T> for &T {
12 fn item_ptr(&self) -> *const T {
13 *self as *const T
14 }
15}
16
17impl<T> SectionItemLocation<T> for &Ref<T> {
18 fn item_ptr(&self) -> *const T {
19 Ref::as_ptr(self)
20 }
21}
22
23impl<T> SectionItemLocation<T> for &MovableRef<T> {
24 fn item_ptr(&self) -> *const T {
25 MovableRef::as_ptr(self)
26 }
27}
28
29pub trait SectionItemType {
31 type Item;
33}
34
35pub trait SectionItemTyped<T> {
39 type Item;
41}
42
43#[cfg(test)]
44mod tests {
45 use crate::item::SectionItemType;
46 use core::marker::PhantomData;
47
48 assert_type_eq!(<crate::TypedSection<u32> as SectionItemType>::Item, u32);
49 assert_type_eq!(
50 <crate::TypedSection<&'static u32> as SectionItemType>::Item,
51 &'static u32
52 );
53
54 macro_rules! assert_type_eq {
55 ($lhs:ty, $rhs:ty) => {
56 const _: () = {
57 struct __AssertTypeEq<T, U>(PhantomData<T>, PhantomData<U>);
58 trait __AssertTypeEqT {
59 const CHECK: bool = true;
60 }
61 impl<T> __AssertTypeEqT for __AssertTypeEq<T, T> {}
62
63 _ = <__AssertTypeEq<$lhs, $rhs> as __AssertTypeEqT>::CHECK;
64 };
65 };
66 }
67 pub(crate) use assert_type_eq;
68}