FIX: Rename ArrayVec .capacity_left() → .remaining_capacity()

This commit is contained in:
bluss
2018-11-28 15:52:46 +01:00
parent d9222c0e61
commit 8e5ff2d0fb
2 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -179,9 +179,9 @@ impl<A: Array> ArrayVec<A> {
/// ///
/// let mut array = ArrayVec::from([1, 2, 3]); /// let mut array = ArrayVec::from([1, 2, 3]);
/// array.pop(); /// 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() self.capacity() - self.len()
} }
@@ -549,14 +549,14 @@ impl<A: Array> ArrayVec<A> {
/// ///
/// # Panics /// # 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. /// 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]) pub fn extend_from_slice(&mut self, other: &[A::Item])
where A::Item: Copy, 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"); panic!("ArrayVec::extend_from_slice: slice is larger then capacity left");
} }
@@ -1079,7 +1079,7 @@ impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
/// Requires `features="std"`. /// Requires `features="std"`.
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> { impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
fn write(&mut self, data: &[u8]) -> io::Result<usize> { fn write(&mut self, data: &[u8]) -> io::Result<usize> {
let len = cmp::min(self.capacity_left(), data.len()); let len = cmp::min(self.remaining_capacity(), data.len());
self.extend_from_slice(&data[..len]); self.extend_from_slice(&data[..len]);
Ok(len) Ok(len)
} }
+5 -5
View File
@@ -30,15 +30,15 @@ fn test_simple() {
#[test] #[test]
fn test_capacity_left() { fn test_capacity_left() {
let mut vec: ArrayVec<[usize; 4]> = ArrayVec::new(); let mut vec: ArrayVec<[usize; 4]> = ArrayVec::new();
assert_eq!(vec.capacity_left(), 4); assert_eq!(vec.remaining_capacity(), 4);
vec.push(1); vec.push(1);
assert_eq!(vec.capacity_left(), 3); assert_eq!(vec.remaining_capacity(), 3);
vec.push(2); vec.push(2);
assert_eq!(vec.capacity_left(), 2); assert_eq!(vec.remaining_capacity(), 2);
vec.push(3); vec.push(3);
assert_eq!(vec.capacity_left(), 1); assert_eq!(vec.remaining_capacity(), 1);
vec.push(4); vec.push(4);
assert_eq!(vec.capacity_left(), 0); assert_eq!(vec.remaining_capacity(), 0);
} }
#[test] #[test]