From cb121725a9f6b8babcdc26ab4c1f2b0f70c2c2a7 Mon Sep 17 00:00:00 2001 From: "J. Rinaldi" <2664441+m-rinaldi@users.noreply.github.com> Date: Sat, 22 Jan 2022 08:46:23 +0100 Subject: [PATCH] Default trait & clippy warnings (#13) --- src/default.rs | 13 +++++++++++++ src/lib.rs | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/default.rs diff --git a/src/default.rs b/src/default.rs new file mode 100644 index 0000000..99bee99 --- /dev/null +++ b/src/default.rs @@ -0,0 +1,13 @@ +use crate::{LocalVec, CopyLocalVec}; + +impl Default for LocalVec { + fn default() -> Self { + Self::new() + } +} + +impl Default for CopyLocalVec { + fn default() -> Self { + Self::new() + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index fd2eb88..b1a10c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] @@ -84,6 +85,10 @@ impl LocalVecImpl { 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; } @@ -116,8 +121,8 @@ impl LocalVecImpl { } 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); }