Make awesome new serious-business doc comment by
contributor into an actually-runnable program.
(I mean, if we're gonna be out here asserting eq like we're
rustc or something, we might as well go all the way!)
@@ -67,22 +67,21 @@ impl<T, const N: usize> StaticVec<T, {N}> {
}
}
- ///Returns a new StaticVec instance filled with the return value of
- ///an initializer function.
+ ///Returns a new StaticVec instance filled with the return value of an initializer function.
///The length field of the newly created StaticVec will be equal to its capacity.
///
///```rust
///use staticvec::*;
///
+ ///fn main() {
/// let mut i = 0;
/// let v = StaticVec::<i32, 64>::filled_with(|| { i += 1; i });
- ///
- /// assert_eq(v.len(), 64);
- ///
- /// assert_eq(v[0], 1);
- /// assert_eq(v[1], 2);
- /// assert_eq(v[2], 3);
- /// assert_eq(v[3], 4);
+ /// assert_eq!(v.len(), 64);
+ /// assert_eq!(v[0], 1);
+ /// assert_eq!(v[1], 2);
+ /// assert_eq!(v[2], 3);
+ /// assert_eq!(v[3], 4);
+ ///}
/// ```
#[inline]
pub fn filled_with<F>(mut initializer: F) -> Self
@@ -172,12 +171,30 @@ impl<T, const N: usize> StaticVec<T, {N}> {
}
}
+ ///Appends a value to the end of the StaticVec without asserting that
+ ///its current length is less than `N`.
+ #[inline(always)]
+ pub unsafe fn push_unchecked(&mut self, value: T) {
+ self.data.get_unchecked_mut(self.length).write(value);
+ self.length += 1;
+ }
+
+ ///Pops a value from the end of the StaticVec and returns it directly without asserting that
+ ///the StaticVec's current length is greater than 0.
+ #[inline(always)]
+ pub unsafe fn pop_unchecked(&mut self) -> T {
+ self.length -= 1;
+ self.data.get_unchecked(self.length).read()
+ }
+
///Asserts that the current length of the StaticVec is less than `N`,
///and if so appends a value to the end of it.
#[inline(always)]
pub fn push(&mut self, value: T) {
assert!(self.length < N);
- unsafe { self.push_unchecked(value); }
+ unsafe {
+ self.push_unchecked(value);
+ }
}
///Removes the value at the last position of the StaticVec and returns it in `Some` if
@@ -191,22 +208,6 @@ impl<T, const N: usize> StaticVec<T, {N}> {
}
}
- ///Appends a value to the end of the StaticVec without asserting that
- ///its current length is less than `N`.
- #[inline(always)]
- pub unsafe fn push_unchecked(&mut self, value: T) {
- self.data.get_unchecked_mut(self.length).write(value);
- self.length += 1;
- }
-
- ///Pops a value from the end of the StaticVec and returns it directly without asserting that
- ///the StaticVec's current length is greater than 0.
- #[inline(always)]
- pub unsafe fn pop_unchecked(&mut self) -> T {
- self.length -= 1;
- self.data.get_unchecked(self.length).read()
- }
-
///Asserts that `index` is less than the current length of the StaticVec,
///and if so removes the value at that position and returns it. Any values
///that exist in later positions are shifted to the left.
