Skip to content

Commit

Permalink
Last few things
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlyoutofphase committed Dec 24, 2021
1 parent fae5016 commit 3627a4d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
15 changes: 7 additions & 8 deletions demo/main_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,22 @@ static BLOCKY: StaticVec<MyOtherStruct, 6> = const {
MyOtherStruct { s: "f" }
];
let mut b = StaticVec::<MyOtherStruct, 6>::new();
let c = staticvec![
let iter_slice = staticvec![
MyOtherStruct { s: "a" },
MyOtherStruct { s: "b" },
MyOtherStruct { s: "c" },
];
let c_slice = c.as_slice();
b.insert(0, c_slice[0].clone());
b.insert(1, c_slice[1].clone());
b.insert(2, c_slice[2].clone());
]
.iter()
.as_slice();
b.insert(0, iter_slice[0].clone());
b.insert(1, iter_slice[1].clone());
b.insert(2, iter_slice[2].clone());
b.append(&mut a);
// `a` is now empty, but we have to "forget" it anyways to make this work in a const context in
// conjunction with the `const_precise_live_drops` feature currently. Note that the reason the
// `build` const fn did not require any use of `mem::forget` is that we only created a single
// StaticVec instance within it which was directly used as the return value.
forget(a);
// `c` must be "forgotten" for the same reasons as `a`.
forget(c);
b
};

Expand Down
45 changes: 28 additions & 17 deletions src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a, T: 'a, const N: usize> DoubleEndedIterator for StaticVecIterConst<'a, T
}
}

impl<'a, T: 'a, const N: usize> ExactSizeIterator for StaticVecIterConst<'a, T, N> {
impl<'a, T: 'a, const N: usize> const ExactSizeIterator for StaticVecIterConst<'a, T, N> {
#[inline(always)]
fn len(&self) -> usize {
distance_between(self.end, self.start)
Expand Down Expand Up @@ -413,7 +413,7 @@ impl<'a, T: 'a, const N: usize> DoubleEndedIterator for StaticVecIterMut<'a, T,
}
}

impl<'a, T: 'a, const N: usize> ExactSizeIterator for StaticVecIterMut<'a, T, N> {
impl<'a, T: 'a, const N: usize> const ExactSizeIterator for StaticVecIterMut<'a, T, N> {
#[inline(always)]
fn len(&self) -> usize {
distance_between(self.end, self.start)
Expand Down Expand Up @@ -618,7 +618,7 @@ impl<T, const N: usize> DoubleEndedIterator for StaticVecIntoIter<T, N> {
}
}

impl<T, const N: usize> ExactSizeIterator for StaticVecIntoIter<T, N> {
impl<T, const N: usize> const ExactSizeIterator for StaticVecIntoIter<T, N> {
#[inline(always)]
fn len(&self) -> usize {
self.end - self.start
Expand All @@ -630,8 +630,8 @@ impl<T, const N: usize> ExactSizeIterator for StaticVecIntoIter<T, N> {
}
}

impl<T, const N: usize> FusedIterator for StaticVecIntoIter<T, N> {}
unsafe impl<T, const N: usize> TrustedLen for StaticVecIntoIter<T, N> {}
impl<T, const N: usize> const FusedIterator for StaticVecIntoIter<T, N> {}
unsafe impl<T, const N: usize> const TrustedLen for StaticVecIntoIter<T, N> {}
// We hide this one just in case it gets removed from `std` later, so no one relies on us relying on
// it.
#[doc(hidden)]
Expand All @@ -642,8 +642,8 @@ unsafe impl<T: Copy, const N: usize> const TrustedRandomAccessNoCoerce for Stati
self.end - self.start
}
}
unsafe impl<T: Sync, const N: usize> Sync for StaticVecIntoIter<T, N> {}
unsafe impl<T: Send, const N: usize> Send for StaticVecIntoIter<T, N> {}
unsafe impl<T: Sync, const N: usize> const Sync for StaticVecIntoIter<T, N> {}
unsafe impl<T: Send, const N: usize> const Send for StaticVecIntoIter<T, N> {}

impl<T: Clone, const N: usize> Clone for StaticVecIntoIter<T, N> {
#[inline(always)]
Expand Down Expand Up @@ -749,7 +749,7 @@ impl<'a, T: 'a, const N: usize> DoubleEndedIterator for StaticVecDrain<'a, T, N>
}
}

impl<'a, T: 'a, const N: usize> ExactSizeIterator for StaticVecDrain<'a, T, N> {
impl<'a, T: 'a, const N: usize> const ExactSizeIterator for StaticVecDrain<'a, T, N> {
#[inline(always)]
fn len(&self) -> usize {
self.iter.len()
Expand All @@ -761,8 +761,8 @@ impl<'a, T: 'a, const N: usize> ExactSizeIterator for StaticVecDrain<'a, T, N> {
}
}

impl<'a, T: 'a, const N: usize> FusedIterator for StaticVecDrain<'a, T, N> {}
unsafe impl<'a, T: 'a, const N: usize> TrustedLen for StaticVecDrain<'a, T, N> {}
impl<'a, T: 'a, const N: usize> const FusedIterator for StaticVecDrain<'a, T, N> {}
unsafe impl<'a, T: 'a, const N: usize> const TrustedLen for StaticVecDrain<'a, T, N> {}
// We hide this one just in case it gets removed from `std` later, so no one relies on us relying on
// it.
#[doc(hidden)]
Expand All @@ -774,8 +774,8 @@ unsafe impl<'a, T: Copy + 'a, const N: usize> const TrustedRandomAccessNoCoerce
distance_between(self.iter.end, self.iter.start)
}
}
unsafe impl<'a, T: 'a + Sync, const N: usize> Sync for StaticVecDrain<'a, T, N> {}
unsafe impl<'a, T: 'a + Send, const N: usize> Send for StaticVecDrain<'a, T, N> {}
unsafe impl<'a, T: 'a + Sync, const N: usize> const Sync for StaticVecDrain<'a, T, N> {}
unsafe impl<'a, T: 'a + Send, const N: usize> const Send for StaticVecDrain<'a, T, N> {}

impl<'a, T: 'a + Debug, const N: usize> Debug for StaticVecDrain<'a, T, N> {
#[inline(always)]
Expand Down Expand Up @@ -871,7 +871,9 @@ impl<T, I: Iterator<Item = T> + DoubleEndedIterator, const N: usize> DoubleEnded
}
}

impl<T, I: Iterator<Item = T>, const N: usize> ExactSizeIterator for StaticVecSplice<T, I, N> {
impl<T, I: Iterator<Item = T>, const N: usize> const ExactSizeIterator
for StaticVecSplice<T, I, N>
{
#[inline(always)]
fn len(&self) -> usize {
self.end - self.start
Expand All @@ -883,10 +885,19 @@ impl<T, I: Iterator<Item = T>, const N: usize> ExactSizeIterator for StaticVecSp
}
}

impl<T, I: Iterator<Item = T>, const N: usize> FusedIterator for StaticVecSplice<T, I, N> {}
unsafe impl<T, I: Iterator<Item = T>, const N: usize> TrustedLen for StaticVecSplice<T, I, N> {}
unsafe impl<T: Sync, I: Iterator<Item = T>, const N: usize> Sync for StaticVecSplice<T, I, N> {}
unsafe impl<T: Send, I: Iterator<Item = T>, const N: usize> Send for StaticVecSplice<T, I, N> {}
impl<T, I: Iterator<Item = T>, const N: usize> const FusedIterator for StaticVecSplice<T, I, N> {}
unsafe impl<T, I: Iterator<Item = T>, const N: usize> const TrustedLen
for StaticVecSplice<T, I, N>
{
}
unsafe impl<T: Sync, I: Iterator<Item = T>, const N: usize> const Sync
for StaticVecSplice<T, I, N>
{
}
unsafe impl<T: Send, I: Iterator<Item = T>, const N: usize> const Send
for StaticVecSplice<T, I, N>
{
}

impl<T: Debug, I: Iterator<Item = T>, const N: usize> Debug for StaticVecSplice<T, I, N> {
#[inline(always)]
Expand Down

0 comments on commit 3627a4d

Please sign in to comment.