design/place/subplace/
indexes.rs1use std::marker::PhantomCovariant;
2
3use crate::{
4 place::Subplace,
5 ptr::Metadata,
6};
7
8pub struct ArrayIndex<T, const LEN: usize>(usize, PhantomCovariant<T>);
9
10impl<T, const LEN: usize> ArrayIndex<T, LEN> {
11 pub unsafe fn new_unchecked(idx: usize) -> Self {
12 if true {
if !(idx < LEN) {
::core::panicking::panic("assertion failed: idx < LEN")
};
};debug_assert!(idx < LEN);
13 Self(idx, PhantomCovariant::new())
14 }
15}
16
17unsafe impl<T, const LEN: usize> Subplace for ArrayIndex<T, LEN> {
18 type Source = [T; LEN];
19 type Target = T;
20
21 fn offset(
22 self,
23 (): Metadata<Self::Source>,
24 ) -> (usize, Metadata<Self::Target>) {
25 const { if !(size_of::<T>().strict_mul(LEN) < isize::MAX as usize) {
::core::panicking::panic("assertion failed: size_of::<T>().strict_mul(LEN) < isize::MAX as usize")
}assert!(size_of::<T>().strict_mul(LEN) < isize::MAX as usize) }
26 if true {
if !(self.0 < LEN) {
::core::panicking::panic("assertion failed: self.0 < LEN")
};
};debug_assert!(self.0 < LEN);
27 (self.0 * size_of::<T>(), ())
28 }
29}
30
31pub struct SliceIndex<T>(usize, PhantomCovariant<T>);
32
33unsafe impl<T> Subplace for SliceIndex<T> {
34 type Source = [T];
35 type Target = T;
36
37 fn offset(
38 self,
39 len: Metadata<Self::Source>,
40 ) -> (usize, Metadata<Self::Target>) {
41 if true {
if !(len * size_of::<T>() < isize::MAX as usize) {
::core::panicking::panic("assertion failed: len * size_of::<T>() < isize::MAX as usize")
};
};debug_assert!(len * size_of::<T>() < isize::MAX as usize);
42 (self.0 * size_of::<T>(), ())
43 }
44}