use crate::{MovableRef, Ref};
pub trait SectionItemLocation<T: ?Sized> {
fn item_ptr(&self) -> *const T;
}
impl<T: ?Sized> SectionItemLocation<T> for &T {
fn item_ptr(&self) -> *const T {
*self as *const T
}
}
impl<T> SectionItemLocation<T> for &Ref<T> {
fn item_ptr(&self) -> *const T {
Ref::as_ptr(self)
}
}
impl<T> SectionItemLocation<T> for &MovableRef<T> {
fn item_ptr(&self) -> *const T {
MovableRef::as_ptr(self)
}
}
pub trait SectionItemType {
type Item;
}
pub trait SectionItemTyped<T> {
type Item;
}
#[cfg(test)]
mod tests {
use crate::item::SectionItemType;
use core::marker::PhantomData;
assert_type_eq!(<crate::TypedSection<u32> as SectionItemType>::Item, u32);
assert_type_eq!(
<crate::TypedSection<&'static u32> as SectionItemType>::Item,
&'static u32
);
macro_rules! assert_type_eq {
($lhs:ty, $rhs:ty) => {
const _: () = {
struct __AssertTypeEq<T, U>(PhantomData<T>, PhantomData<U>);
trait __AssertTypeEqT {
const CHECK: bool = true;
}
impl<T> __AssertTypeEqT for __AssertTypeEq<T, T> {}
_ = <__AssertTypeEq<$lhs, $rhs> as __AssertTypeEqT>::CHECK;
};
};
}
pub(crate) use assert_type_eq;
}