From 8e5ff2d0fba33823e0c7023ac19284295e1dcbee Mon Sep 17 00:00:00 2001 From: bluss Date: Wed, 28 Nov 2018 15:52:46 +0100 Subject: [PATCH] =?UTF-8?q?FIX:=20Rename=20ArrayVec=20.capacity=5Fleft()?= =?UTF-8?q?=20=E2=86=92=20.remaining=5Fcapacity()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 12 ++++++------ tests/tests.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9df8126..4d83a1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,9 +179,9 @@ impl ArrayVec { /// /// let mut array = ArrayVec::from([1, 2, 3]); /// array.pop(); - /// assert_eq!(array.capacity_left(), 1); + /// assert_eq!(array.remaining_capacity(), 1); /// ``` - pub fn capacity_left(&self) -> usize { + pub fn remaining_capacity(&self) -> usize { self.capacity() - self.len() } @@ -549,14 +549,14 @@ impl ArrayVec { /// /// # Panics /// - /// This method will panic if the capacity left (see [`capacity_left`]) is + /// This method will panic if the capacity left (see [`remaining_capacity`]) is /// smaller then the length of the provided slice. /// - /// [`capacity_left`]: #method.capacity_left + /// [`remaining_capacity`]: #method.remaining_capacity pub fn extend_from_slice(&mut self, other: &[A::Item]) where A::Item: Copy, { - if self.capacity_left() < other.len() { + if self.remaining_capacity() < other.len() { panic!("ArrayVec::extend_from_slice: slice is larger then capacity left"); } @@ -1079,7 +1079,7 @@ impl Ord for ArrayVec where A::Item: Ord { /// Requires `features="std"`. impl> io::Write for ArrayVec { fn write(&mut self, data: &[u8]) -> io::Result { - let len = cmp::min(self.capacity_left(), data.len()); + let len = cmp::min(self.remaining_capacity(), data.len()); self.extend_from_slice(&data[..len]); Ok(len) } diff --git a/tests/tests.rs b/tests/tests.rs index a638de9..5b8b5e4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -30,15 +30,15 @@ fn test_simple() { #[test] fn test_capacity_left() { let mut vec: ArrayVec<[usize; 4]> = ArrayVec::new(); - assert_eq!(vec.capacity_left(), 4); + assert_eq!(vec.remaining_capacity(), 4); vec.push(1); - assert_eq!(vec.capacity_left(), 3); + assert_eq!(vec.remaining_capacity(), 3); vec.push(2); - assert_eq!(vec.capacity_left(), 2); + assert_eq!(vec.remaining_capacity(), 2); vec.push(3); - assert_eq!(vec.capacity_left(), 1); + assert_eq!(vec.remaining_capacity(), 1); vec.push(4); - assert_eq!(vec.capacity_left(), 0); + assert_eq!(vec.remaining_capacity(), 0); } #[test]