Skip to content

Commit 7b97ffc

Browse files
author
bors-servo
authored
Auto merge of #38 - Marwes:deref_slice, r=jdm
Specify that VecLike derefs to a slice I believe this is just an oversight. Since `<[T]>::len` is now available through the `Deref` bound I also removed `VecLike::len`. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/38) <!-- Reviewable:end -->
2 parents a47e255 + 7e9787f commit 7b97ffc

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smallvec"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
authors = ["Simon Sapin <[email protected]>"]
55
license = "MPL-2.0"
66
repository = "https://github.com/servo/rust-smallvec"

lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,13 @@ pub trait VecLike<T>:
2929
ops::IndexMut<ops::RangeTo<usize>> +
3030
ops::Index<ops::RangeFull, Output=[T]> +
3131
ops::IndexMut<ops::RangeFull> +
32-
ops::Deref +
33-
ops::DerefMut +
32+
ops::DerefMut<Target = [T]> +
3433
Extend<T> {
3534

36-
fn len(&self) -> usize;
3735
fn push(&mut self, value: T);
3836
}
3937

4038
impl<T> VecLike<T> for Vec<T> {
41-
#[inline]
42-
fn len(&self) -> usize {
43-
Vec::len(self)
44-
}
4539

4640
#[inline]
4741
fn push(&mut self, value: T) {
@@ -150,12 +144,15 @@ impl<A: Array> SmallVec<A> {
150144
pub fn inline_size(&self) -> usize {
151145
A::size()
152146
}
147+
153148
pub fn len(&self) -> usize {
154149
self.len
155150
}
151+
156152
pub fn is_empty(&self) -> bool {
157153
self.len == 0
158154
}
155+
159156
pub fn capacity(&self) -> usize {
160157
match self.data {
161158
Inline { .. } => A::size(),
@@ -401,11 +398,6 @@ impl_index!(ops::RangeFull, [A::Item]);
401398

402399

403400
impl<A: Array> VecLike<A::Item> for SmallVec<A> {
404-
#[inline]
405-
fn len(&self) -> usize {
406-
SmallVec::len(self)
407-
}
408-
409401
#[inline]
410402
fn push(&mut self, value: A::Item) {
411403
SmallVec::push(self, value);
@@ -1014,4 +1006,20 @@ pub mod tests {
10141006
assert_eq!(vec.clone().into_iter().len(), 3);
10151007
assert_eq!(vec.drain().len(), 3);
10161008
}
1009+
1010+
#[test]
1011+
fn veclike_deref_slice() {
1012+
use super::VecLike;
1013+
1014+
fn test<T: VecLike<i32>>(vec: &mut T) {
1015+
assert!(!vec.is_empty());
1016+
assert_eq!(vec.len(), 3);
1017+
1018+
vec.sort();
1019+
assert_eq!(&vec[..], [1, 2, 3]);
1020+
}
1021+
1022+
let mut vec = SmallVec::<[i32; 2]>::from(&[3, 1, 2][..]);
1023+
test(&mut vec);
1024+
}
10171025
}

0 commit comments

Comments
 (0)