From 5c6d00e4443329fad5325a0916bd4c6e29d7f75d Mon Sep 17 00:00:00 2001 From: nsan1129 Date: Mon, 25 Sep 2017 15:28:36 -0700 Subject: [PATCH] Implement `as_slice` and `as_mut_slice` methods. --- lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib.rs b/lib.rs index 9cfe759..0fba76a 100644 --- a/lib.rs +++ b/lib.rs @@ -530,6 +530,20 @@ impl SmallVec { } } + /// Extracts a slice containing the entire vector. + /// + /// Equivalent to `&mut s[..]`. + pub fn as_slice(&self) -> &[A::Item] { + self + } + + /// Extracts a mutable slice of the entire vector. + /// + /// Equivalent to `&mut s[..]`. + pub fn as_mut_slice(&mut self) -> &mut [A::Item] { + self + } + /// Remove the element at position `index`, replacing it with the last element. /// /// This does not preserve ordering, but is O(1).