Expose ArrayVec::set_len as a pub unsafe method

This commit is contained in:
root
2015-06-22 00:17:23 +02:00
parent 5ae6e1aadc
commit 66d5d9a12e
+13 -5
View File
@@ -90,11 +90,6 @@ impl<A: Array> ArrayVec<A> {
#[inline] #[inline]
pub fn len(&self) -> usize { self.len.to_usize() } pub fn len(&self) -> usize { self.len.to_usize() }
unsafe fn set_len(&mut self, length: usize) {
debug_assert!(length <= self.capacity());
self.len = Index::from(length);
}
/// Return the capacity of the **ArrayVec**. /// Return the capacity of the **ArrayVec**.
/// ///
/// ## Examples /// ## Examples
@@ -265,6 +260,19 @@ impl<A: Array> ArrayVec<A> {
while let Some(_) = self.pop() { } while let Some(_) = self.pop() { }
} }
/// Set the vector's length without dropping or moving out elements
///
/// May panic if **length** is greater than the capacity.
///
/// This function is **unsafe** because it changes the notion of the
/// number of “valid” elements in the vector. Use with care.
#[inline]
pub unsafe fn set_len(&mut self, length: usize) {
debug_assert!(length <= self.capacity());
self.len = Index::from(length);
}
/// Create a draining iterator that removes the specified range in the vector /// Create a draining iterator that removes the specified range in the vector
/// and yields the removed items from start to end. The element range is /// and yields the removed items from start to end. The element range is
/// removed even if the iterator is not consumed until the end. /// removed even if the iterator is not consumed until the end.