1use std::mem;
2
3use crate::alloc;
4
5pub unsafe trait Rows: alloc::raw::Shape {
9 const ROOT_MAX: usize = match mem::size_of::<Self::Root>() {
10 0 => usize::MAX,
11 size => isize::MAX as usize / size,
12 };
13
14 const MAX: usize = {
15 let root = mem::align_of::<Self::Root>();
16 let tail = mem::align_of::<Self::Tail>();
17 let align = if root > tail { root } else { tail };
18 let bound = (isize::MAX as usize) & !(align - 1);
19 match mem::size_of::<Self::Root>() + mem::size_of::<Self::Tail>() {
20 0 => usize::MAX,
21 size => bound / size,
22 }
23 };
24
25 const EXTRA_MAX: usize = {
26 let mut low = 0;
27 let mut high = Self::MAX;
28 while low < high {
29 let span = high - low;
30 let count = low + span.div_ceil(2);
31 if alloc::raw::Bundle::bounds::<Self>(count, count).fits() {
32 low = count;
33 } else {
34 high = count - 1;
35 }
36 }
37 low
38 };
39}