use core::marker::PhantomData;
use core::num::NonZeroUsize;
use core::ops::{Range, RangeFrom, RangeTo};
pub unsafe trait Tag: Copy {}
#[derive(Clone, Copy)]
pub struct Generative<'lt> {
generated: PhantomData<&'lt fn(&'lt [()])>,
}
unsafe impl Tag for Generative<'_> {}
pub struct Named<T> {
phantom: PhantomData<T>,
}
pub fn with_ref<'slice, T, U>(
slice: &'slice [T],
f: impl for<'r> FnOnce(&'slice Slice<T, Generative<'r>>, ExactSize<Generative<'r>>) -> U,
) -> U {
let len = ExactSize {
inner: Len {
len: slice.len(),
tag: Generative {
generated: PhantomData,
},
},
};
let slice = unsafe { Slice::new_unchecked(slice, len.inner.tag) };
f(slice, len)
}
pub fn with_mut<'slice, T, U>(
slice: &'slice mut [T],
f: impl for<'r> FnOnce(&'slice mut Slice<T, Generative<'r>>, ExactSize<Generative<'r>>) -> U,
) -> U {
let len = ExactSize {
inner: Len {
len: slice.len(),
tag: Generative {
generated: PhantomData,
},
},
};
let slice = unsafe { Slice::new_unchecked_mut(slice, len.inner.tag) };
f(slice, len)
}
#[derive(Clone, Copy)]
pub struct Len<Tag> {
len: usize,
tag: Tag,
}
#[derive(Clone, Copy)]
pub struct Capacity<Tag> {
len: usize,
tag: Tag,
}
#[derive(Clone, Copy)]
pub struct NonZeroLen<Tag> {
len: NonZeroUsize,
tag: Tag,
}
#[derive(Clone, Copy)]
pub struct ExactSize<Tag> {
inner: Len<Tag>,
}
#[derive(Clone, Copy)]
pub struct LessEq<TagA, TagB> {
a: TagA,
b: TagB,
}
#[derive(Clone, Copy)]
pub struct Eq<TagA, TagB> {
a: TagA,
b: TagB,
}
pub struct Slice<T, Tag> {
#[allow(dead_code)]
tag: Tag,
slice: [T],
}
#[cfg(feature = "alloc")]
pub struct Boxed<T, Tag> {
inner: alloc::boxed::Box<[T]>,
tag: Tag,
}
pub trait ConstantSource {
const LEN: usize;
}
pub struct Constant<T>(PhantomData<fn(&mut T) -> T>);
unsafe impl<T: ConstantSource> Tag for Constant<T> {}
#[derive(Clone, Copy)]
pub struct Const<const N: usize>;
unsafe impl<const N: usize> Tag for Const<N> {}
#[derive(Clone, Copy)]
pub struct Idx<I, Tag> {
idx: I,
tag: Tag,
}
#[cfg(feature = "alloc")]
pub struct IdxBox<Idx> {
indices: alloc::boxed::Box<[Idx]>,
exact_size: usize,
}
impl<T: Tag> Len<T> {
pub fn with_tag<NewT>(self, less: LessEq<T, NewT>) -> Len<NewT> {
let len = self.len;
let tag = less.b;
Len { len, tag }
}
#[must_use = "Is a no-op. Use the returned length."]
pub fn get(self) -> usize {
self.len
}
#[must_use = "Returns a new index"]
pub fn index(self, idx: usize) -> Option<Idx<usize, T>> {
if idx < self.len {
Some(Idx { idx, tag: self.tag })
} else {
None
}
}
#[must_use = "Returns a new index"]
pub fn range(self, from: usize, to: usize) -> Option<Idx<core::ops::Range<usize>, T>> {
if from <= to && to <= self.len {
Some(Idx {
idx: from..to,
tag: self.tag,
})
} else {
None
}
}
#[must_use = "Returns a new index"]
pub fn range_from(self, from: usize) -> Option<Idx<core::ops::RangeFrom<usize>, T>> {
if from <= self.len {
Some(Idx {
idx: from..,
tag: self.tag,
})
} else {
None
}
}
#[must_use = "Returns a new index"]
pub fn range_from_self(self) -> Idx<core::ops::RangeFrom<usize>, T> {
Idx {
idx: self.len..,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn range_to(self, to: usize) -> Option<Idx<core::ops::RangeTo<usize>, T>> {
if to <= self.len {
Some(Idx {
idx: ..to,
tag: self.tag,
})
} else {
None
}
}
#[must_use = "Returns a new index"]
pub fn range_to_self(self) -> Idx<core::ops::RangeTo<usize>, T> {
Idx {
idx: ..self.len,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn range_between(self, other: Self) -> Idx<core::ops::Range<usize>, T> {
Idx {
idx: self.len.min(other.len)..self.len.max(other.len),
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn range_full(self) -> Idx<core::ops::RangeFull, T> {
Idx {
idx: ..,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn saturating_sub(self, sub: usize) -> Self {
Len {
len: self.len.saturating_sub(sub),
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn truncate(self, min: usize) -> Self {
Len {
len: self.len.min(min),
tag: self.tag,
}
}
}
impl<T: Tag> Capacity<T> {
pub fn with_tag<NewT>(self, less: LessEq<NewT, T>) -> Capacity<NewT> {
let len = self.len;
let tag = less.a;
Capacity { len, tag }
}
#[must_use = "Is a no-op. Use the returned length."]
pub fn get(self) -> usize {
self.len
}
#[must_use = "Returns a new capacity"]
pub fn saturating_add(self, add: usize) -> Self {
Capacity {
len: self.len.saturating_add(add),
tag: self.tag,
}
}
#[must_use = "Returns a new capacity"]
pub fn ensure(self, min: usize) -> Self {
Capacity {
len: self.len.max(min),
tag: self.tag,
}
}
}
impl<T: Tag> NonZeroLen<T> {
pub fn new(complete: Len<T>) -> Option<Self> {
let len = NonZeroUsize::new(complete.len)?;
Some(NonZeroLen {
len,
tag: complete.tag,
})
}
pub fn with_tag<NewT>(self, less: LessEq<T, NewT>) -> NonZeroLen<NewT> {
let len = self.len;
let tag = less.b;
NonZeroLen { len, tag }
}
#[must_use = "Returns a new index"]
pub fn first(self) -> Idx<usize, T> {
Idx {
idx: 0,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn last(self) -> Idx<usize, T> {
Idx {
idx: self.len.get() - 1,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn into_len(self) -> Len<T> {
Len {
len: self.len.get(),
tag: self.tag,
}
}
#[must_use = "Is a no-op. Use the returned length."]
pub fn get(self) -> NonZeroUsize {
self.len
}
}
impl<T> ExactSize<T> {
pub const unsafe fn new_untagged(len: usize, tag: T) -> Self {
ExactSize {
inner: Len { len, tag },
}
}
pub const unsafe fn from_len_untagged(bound: Len<T>) -> Self {
ExactSize { inner: bound }
}
#[must_use = "Is a no-op. Use the returned length."]
pub const fn get(&self) -> usize {
self.inner.len
}
}
impl<'lt> Generative<'lt> {
pub fn with_len(len: usize, token: generativity::Guard<'lt>) -> ExactSize<Self> {
ExactSize::with_guard(len, token)
}
pub fn with_ref<'slice, T>(
slice: &'slice [T],
token: generativity::Guard<'lt>,
) -> (&'slice Slice<T, Self>, ExactSize<Self>) {
let size = ExactSize::with_guard(slice.len(), token);
let ref_ = unsafe { Slice::new_unchecked(slice, size.inner.tag) };
(ref_, size)
}
pub fn with_mut<'slice, T>(
slice: &'slice mut [T],
token: generativity::Guard<'lt>,
) -> (&'slice mut Slice<T, Self>, ExactSize<Self>) {
let size = ExactSize::with_guard(slice.len(), token);
let ref_ = unsafe { Slice::new_unchecked_mut(slice, size.inner.tag) };
(ref_, size)
}
}
impl<'lt> ExactSize<Generative<'lt>> {
pub fn with_guard(len: usize, _: generativity::Guard<'lt>) -> Self {
ExactSize {
inner: Len {
len,
tag: Generative {
generated: PhantomData,
},
},
}
}
}
impl<T: Tag> ExactSize<T> {
pub unsafe fn new(len: usize, tag: T) -> Self {
unsafe { Self::new_untagged(len, tag) }
}
pub unsafe fn from_len(len: Len<T>) -> Self {
unsafe { Self::from_len_untagged(len) }
}
pub unsafe fn from_capacity(cap: Capacity<T>) -> Self {
unsafe { Self::new_untagged(cap.len, cap.tag) }
}
pub fn with_tag<NewT>(self, equality: Eq<T, NewT>) -> ExactSize<NewT> {
let len = self.inner.len;
let tag = equality.b;
ExactSize {
inner: Len { len, tag },
}
}
#[must_use = "Returns a new index"]
pub fn into_len(self) -> Len<T> {
self.inner
}
#[must_use = "Returns a new index"]
pub fn into_capacity(self) -> Capacity<T> {
Capacity {
len: self.inner.len,
tag: self.inner.tag,
}
}
pub fn with_matching_pair(len: Len<T>, cap: Capacity<T>) -> Option<Self> {
if len.get() == cap.get() {
Some(ExactSize {
inner: Len {
len: len.get(),
tag: len.tag,
},
})
} else {
None
}
}
}
impl<A: Tag> Eq<A, A> {
pub fn reflexive(tag: A) -> Self {
Eq { a: tag, b: tag }
}
}
impl<A: Tag, B: Tag> Eq<A, B> {
pub fn new(lhs: LessEq<A, B>, _: LessEq<B, A>) -> Self {
Eq { a: lhs.a, b: lhs.b }
}
pub fn transpose(self) -> Eq<B, A> {
Eq {
a: self.b,
b: self.a,
}
}
pub fn into_le(self) -> LessEq<A, B> {
LessEq {
a: self.a,
b: self.b,
}
}
}
impl<A: Tag> LessEq<A, A> {
pub fn reflexive(tag: A) -> Self {
LessEq { a: tag, b: tag }
}
}
impl<A: Tag, B: Tag> LessEq<A, B> {
pub fn with_sizes(a: ExactSize<A>, b: ExactSize<B>) -> Option<Self> {
if a.get() <= b.get() {
Some(LessEq {
a: a.inner.tag,
b: b.inner.tag,
})
} else {
None
}
}
pub fn with_pair(a: Capacity<A>, b: Len<B>) -> Option<Self> {
if b.get() >= a.get() {
Some(LessEq { a: a.tag, b: b.tag })
} else {
None
}
}
}
impl<T> Named<T> {
pub const fn new(t: T) -> Self {
let _ = core::mem::ManuallyDrop::new(t);
Named {
phantom: PhantomData,
}
}
}
unsafe impl<T> Tag for Named<T> {}
impl<T: Tag> From<NonZeroLen<T>> for Len<T> {
fn from(from: NonZeroLen<T>) -> Self {
Len {
len: from.len.get(),
tag: from.tag,
}
}
}
impl<T, I> Idx<I, T> {
pub fn into_inner(self) -> I {
self.idx
}
pub fn with_tag<NewT>(self, larger: LessEq<T, NewT>) -> Idx<I, NewT> {
Idx {
idx: self.idx,
tag: larger.b,
}
}
}
impl<T> Idx<usize, T> {
#[must_use = "Returns a new index"]
pub fn saturating_sub(self, sub: usize) -> Self {
Idx {
idx: self.idx.saturating_sub(sub),
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn truncate(self, min: usize) -> Self {
Idx {
idx: self.idx.min(min),
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn into_range(self) -> Idx<core::ops::Range<usize>, T> {
Idx {
idx: self.idx..self.idx + 1,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn into_len(self) -> Len<T> {
Len {
len: self.idx,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn into_end(self) -> NonZeroLen<T> {
NonZeroLen {
len: NonZeroUsize::new(self.idx + 1).unwrap(),
tag: self.tag,
}
}
}
impl<T> Idx<RangeTo<usize>, T> {
#[must_use = "Returns a new index"]
pub fn into_end(self) -> Len<T> {
Len {
len: self.idx.end,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn range_from(self, from: Len<T>) -> Option<Idx<core::ops::Range<usize>, T>> {
if from.len <= self.idx.end {
Some(Idx {
idx: from.len..self.idx.end,
tag: self.tag,
})
} else {
None
}
}
}
impl<T> Idx<RangeFrom<usize>, T> {
#[must_use = "Returns a new index"]
pub fn into_start(self) -> Len<T> {
Len {
len: self.idx.start,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn range_to(self, to: Len<T>) -> Option<Idx<core::ops::Range<usize>, T>> {
if to.len >= self.idx.start {
Some(Idx {
idx: self.idx.start..to.len,
tag: self.tag,
})
} else {
None
}
}
}
impl<T> Idx<Range<usize>, T> {
#[must_use = "Returns a new index"]
pub fn into_start(self) -> Len<T> {
Len {
len: self.idx.start,
tag: self.tag,
}
}
#[must_use = "Returns a new index"]
pub fn into_end(self) -> Len<T> {
Len {
len: self.idx.end,
tag: self.tag,
}
}
}
#[allow(unused_unsafe)]
impl<T: Tag, E> Slice<E, T> {
pub fn new(slice: &[E], size: ExactSize<T>) -> Option<&'_ Self> {
if slice.len() >= size.into_len().get() {
Some(unsafe { Self::new_unchecked(slice, size.inner.tag) })
} else {
None
}
}
pub fn new_mut(slice: &mut [E], size: ExactSize<T>) -> Option<&'_ mut Self> {
if slice.len() >= size.into_len().get() {
Some(unsafe { Self::new_unchecked_mut(slice, size.inner.tag) })
} else {
None
}
}
pub unsafe fn new_unchecked(slice: &[E], _: T) -> &'_ Self {
unsafe { &*(slice as *const [E] as *const Self) }
}
pub unsafe fn new_unchecked_mut(slice: &mut [E], _: T) -> &'_ mut Self {
unsafe { &mut *(slice as *mut [E] as *mut Self) }
}
pub fn with_tag<NewT: Tag>(&self, _: LessEq<NewT, T>) -> &'_ Slice<E, NewT> {
unsafe { &*(self as *const Self as *const Slice<E, NewT>) }
}
pub fn with_tag_mut<NewT: Tag>(&mut self, _: LessEq<NewT, T>) -> &'_ mut Slice<E, NewT> {
unsafe { &mut *(self as *mut Self as *mut Slice<E, NewT>) }
}
pub fn capacity(&self) -> Capacity<T> {
Capacity {
len: self.slice.len(),
tag: self.tag,
}
}
}
impl<T, E> Slice<E, T> {
pub fn get_safe<I: core::slice::SliceIndex<[E]>>(&self, index: Idx<I, T>) -> &I::Output {
unsafe { self.slice.get_unchecked(index.idx) }
}
pub fn get_safe_mut<I: core::slice::SliceIndex<[E]>>(
&mut self,
index: Idx<I, T>,
) -> &mut I::Output {
unsafe { self.slice.get_unchecked_mut(index.idx) }
}
}
#[cfg(feature = "alloc")]
impl<T: Tag, E> Boxed<E, T> {
pub fn new(
inner: alloc::boxed::Box<[E]>,
len: ExactSize<T>,
) -> Result<Self, alloc::boxed::Box<[E]>> {
match Slice::new(&*inner, len) {
Some(_) => Ok(Boxed {
inner,
tag: len.inner.tag,
}),
None => Err(inner),
}
}
pub fn as_ref(&self) -> &'_ Slice<E, T> {
unsafe { Slice::new_unchecked(&*self.inner, self.tag) }
}
pub fn as_mut(&mut self) -> &'_ mut Slice<E, T> {
unsafe { Slice::new_unchecked_mut(&mut *self.inner, self.tag) }
}
pub fn capacity(&self) -> Capacity<T> {
Capacity {
len: self.inner.len(),
tag: self.tag,
}
}
pub fn get_safe<I: core::slice::SliceIndex<[E]>>(&self, index: Idx<I, T>) -> &I::Output {
self.as_ref().get_safe(index)
}
pub fn get_safe_mut<I: core::slice::SliceIndex<[E]>>(
&mut self,
index: Idx<I, T>,
) -> &mut I::Output {
self.as_mut().get_safe_mut(index)
}
pub fn into_inner(self) -> alloc::boxed::Box<[E]> {
self.inner
}
}
impl<E, T> core::ops::Deref for Slice<E, T> {
type Target = [E];
fn deref(&self) -> &[E] {
&self.slice
}
}
impl<E, T> core::ops::DerefMut for Slice<E, T> {
fn deref_mut(&mut self) -> &mut [E] {
&mut self.slice
}
}
impl<T: Tag, E, I> core::ops::Index<Idx<I, T>> for Slice<E, T>
where
I: core::slice::SliceIndex<[E]>,
{
type Output = I::Output;
fn index(&self, idx: Idx<I, T>) -> &Self::Output {
self.get_safe(idx)
}
}
impl<T: Tag, E, I> core::ops::IndexMut<Idx<I, T>> for Slice<E, T>
where
I: core::slice::SliceIndex<[E]>,
{
fn index_mut(&mut self, idx: Idx<I, T>) -> &mut Self::Output {
self.get_safe_mut(idx)
}
}
impl<T> Clone for Named<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T> Copy for Named<T> {}
impl<T> Clone for Constant<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T> Copy for Constant<T> {}
impl<T: ConstantSource> Constant<T> {
pub const EXACT_SIZE: ExactSize<Self> =
unsafe { ExactSize::new_untagged(T::LEN, Constant(PhantomData)) };
}
impl<const N: usize> Const<N> {
pub const EXACT_SIZE: ExactSize<Self> =
unsafe { ExactSize::new_untagged(N, Const) };
pub fn to_ref<T>(self, arr: &[T; N]) -> &'_ Slice<T, Self> {
unsafe { Slice::new_unchecked(&arr[..], self) }
}
#[allow(clippy::wrong_self_convention)]
pub fn to_mut<T>(self, arr: &mut [T; N]) -> &'_ mut Slice<T, Self> {
unsafe { Slice::new_unchecked_mut(&mut arr[..], self) }
}
}
#[cfg(feature = "alloc")]
mod impl_of_boxed_idx {
use super::{ExactSize, Idx, IdxBox, Len, Tag};
use core::ops::{RangeFrom, RangeTo};
pub trait HiddenMaxIndex: Sized {
fn exclusive_upper_bound(this: &[Self]) -> Option<usize>;
}
impl HiddenMaxIndex for usize {
fn exclusive_upper_bound(this: &[Self]) -> Option<usize> {
this.iter()
.copied()
.max()
.map_or(Some(0), |idx| idx.checked_add(1))
}
}
impl HiddenMaxIndex for RangeFrom<usize> {
fn exclusive_upper_bound(this: &[Self]) -> Option<usize> {
this.iter().map(|range| range.start).max()
}
}
impl HiddenMaxIndex for RangeTo<usize> {
fn exclusive_upper_bound(this: &[Self]) -> Option<usize> {
this.iter().map(|range| range.end).max()
}
}
impl<I: HiddenMaxIndex> IdxBox<I> {
pub fn new(indices: alloc::boxed::Box<[I]>) -> Result<Self, alloc::boxed::Box<[I]>> {
match HiddenMaxIndex::exclusive_upper_bound(&indices[..]) {
Some(upper_bound) => Ok(IdxBox {
indices,
exact_size: upper_bound,
}),
None => Err(indices),
}
}
pub fn bound(&self) -> usize {
self.exact_size
}
pub fn ensure(&mut self, min: usize) {
self.exact_size = self.exact_size.max(min);
}
pub fn truncate(&mut self) {
let least_bound = HiddenMaxIndex::exclusive_upper_bound(&self.indices)
.expect("Some upper bound must still apply");
debug_assert!(
self.exact_size >= least_bound,
"The exact size was corrupted to be below the least bound."
);
self.exact_size = least_bound;
}
pub fn as_ref<T: Tag>(&self, size: Len<T>) -> Option<&'_ [Idx<I, T>]> {
if size.get() >= self.exact_size {
Some(unsafe {
let content: *const [I] = &self.indices[..];
&*(content as *const [Idx<I, T>])
})
} else {
None
}
}
pub fn as_mut<T: Tag>(&mut self, size: ExactSize<T>) -> Option<&'_ mut [Idx<I, T>]> {
if size.get() == self.exact_size {
Some(unsafe {
let content: *mut [I] = &mut self.indices[..];
&mut *(content as *mut [Idx<I, T>])
})
} else {
None
}
}
}
}
#[cfg(test)]
mod tests {
use super::{with_ref, Constant, ConstantSource, Eq, LessEq, Slice};
#[test]
fn basics() {
fn problematic(buf: &mut [u8], offsets: &[u8], idx: usize) {
with_ref(&offsets[..=idx], |offsets, size| {
let mut idx = size.into_len().index(idx).unwrap();
for b in buf {
*b = idx.into_inner() as u8;
idx = idx.saturating_sub(usize::from(offsets[idx]));
}
})
}
let mut output = [0; 3];
let offsets = [1, 0, 2, 2];
problematic(&mut output, &offsets[..], 3);
assert_eq!(output, [3, 1, 1]);
}
#[test]
fn tag_switching() {
struct ConstantLen;
impl ConstantSource for ConstantLen {
const LEN: usize = 4;
}
let mut buffer = [0u8; 4];
let csize = Constant::<ConstantLen>::EXACT_SIZE;
let slice = Slice::new_mut(&mut buffer[..], csize).unwrap();
assert_eq!(slice.len(), ConstantLen::LEN);
let all = csize.into_len().range_to_self();
with_ref(&buffer[..], |slice, size| {
let lesseq = LessEq::with_sizes(size, csize).unwrap();
let moreeq = LessEq::with_sizes(csize, size).unwrap();
let eq = Eq::new(lesseq, moreeq).transpose();
let all = all.with_tag(eq.into_le());
let safe = slice.get_safe(all);
assert_eq!(safe.len(), ConstantLen::LEN);
assert_eq!(csize.with_tag(eq).get(), csize.get());
});
}
#[test]
fn bad_inequalities() {
struct SmallLen;
struct LargeLen;
impl ConstantSource for SmallLen {
const LEN: usize = 1;
}
impl ConstantSource for LargeLen {
const LEN: usize = 2;
}
let small = Constant::<SmallLen>::EXACT_SIZE;
let large = Constant::<LargeLen>::EXACT_SIZE;
assert!(
LessEq::with_pair(small.into_capacity(), large.into_len()).is_some(),
"Small is in fact less than large"
);
assert!(
LessEq::with_pair(large.into_capacity(), small.into_len()).is_none(),
"Large should not appear less than small"
);
}
#[test]
#[cfg(feature = "alloc")]
fn idx_boxing() {
use super::IdxBox;
use alloc::boxed::Box;
struct ExactBound;
struct LargerBound;
impl ConstantSource for ExactBound {
const LEN: usize = 3;
}
impl ConstantSource for LargerBound {
const LEN: usize = 4;
}
let indices = Box::from([0, 1, 2]);
let mut boxed = IdxBox::new(indices).expect("Have a valid upper bound");
assert_eq!(boxed.bound(), <ExactBound as ConstantSource>::LEN);
let exact = Constant::<ExactBound>::EXACT_SIZE;
boxed.as_ref(exact.into_len()).expect("A valid upper bound");
let larger = Constant::<LargerBound>::EXACT_SIZE;
boxed
.as_ref(larger.into_len())
.expect("A valid upper bound");
boxed.as_mut(exact).expect("A valid exact bound");
assert!(boxed.as_mut(larger).is_none(), "An invalid exact bound");
boxed.ensure(larger.get());
assert_eq!(boxed.bound(), <LargerBound as ConstantSource>::LEN);
assert!(
boxed.as_mut(exact).is_none(),
"No longer a valid exact bound"
);
boxed.as_mut(larger).expect("Now a valid exact bound");
boxed.truncate();
assert_eq!(boxed.bound(), <ExactBound as ConstantSource>::LEN);
boxed.as_mut(exact).expect("A valid exact bound");
assert!(boxed.as_mut(larger).is_none(), "An invalid exact bound");
}
}
extern "C" {}