Skip to content

Commit

Permalink
Default trait & clippy warnings (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-rinaldi authored Jan 22, 2022
1 parent 4fa0db4 commit cb12172
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::{LocalVec, CopyLocalVec};

impl<T, const N: usize> Default for LocalVec<T, N> {
fn default() -> Self {
Self::new()
}
}

impl<T: Copy, const N: usize> Default for CopyLocalVec<T, N> {
fn default() -> Self {
Self::new()
}
}
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod deref;
mod iter;
mod extend;
mod eq;
mod default;

/// A fixed-capacity vector that directly stores its elements
#[derive(Eq, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -84,6 +85,10 @@ impl<T, const N: usize> LocalVecImpl<T, N> {
self.len
}

/// Forces the length of the local vector to `new_len`
/// # Safety
/// - `new_len` must be less than or equal to [`capacity()`].
/// - The elements at `old_len..new_len` must be initialized.
pub unsafe fn set_len(&mut self, len: usize) {
self.len = len;
}
Expand Down Expand Up @@ -116,8 +121,8 @@ impl<T, const N: usize> LocalVecImpl<T, N> {
}

pub fn clear(&mut self) {
while let Some(_) = self.pop() {
}
// TODO order should be the opposite of this (due to drop order)
while self.pop().is_some() {}
debug_assert_eq!(self.len, 0);
}

Expand Down

0 comments on commit cb12172

Please sign in to comment.