Skip to content

Commit 304216c

Browse files
Use SliceIndex trait for SmallVec's Index trait
Requires Rust 1.28.0.
1 parent 3ee6d1e commit 304216c

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: rust
22
rust:
3-
- 1.20.0
3+
- 1.36.0
44
- nightly
55
- beta
66
- stable

lib.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use std::mem::ManuallyDrop;
6060
use std::ops;
6161
use std::ptr;
6262
use std::slice;
63+
use std::slice::SliceIndex;
6364
#[cfg(feature = "std")]
6465
use std::io;
6566
#[cfg(feature = "serde")]
@@ -1291,30 +1292,19 @@ impl<A: Array> From<A> for SmallVec<A> {
12911292
}
12921293
}
12931294

1294-
macro_rules! impl_index {
1295-
($index_type: ty, $output_type: ty) => {
1296-
impl<A: Array> ops::Index<$index_type> for SmallVec<A> {
1297-
type Output = $output_type;
1298-
#[inline]
1299-
fn index(&self, index: $index_type) -> &$output_type {
1300-
&(&**self)[index]
1301-
}
1302-
}
1295+
impl<A: Array, T: SliceIndex<[A::Item]>> ops::Index<T> for SmallVec<A> {
1296+
type Output = T::Output;
13031297

1304-
impl<A: Array> ops::IndexMut<$index_type> for SmallVec<A> {
1305-
#[inline]
1306-
fn index_mut(&mut self, index: $index_type) -> &mut $output_type {
1307-
&mut (&mut **self)[index]
1308-
}
1309-
}
1298+
fn index(&self, index: T) -> &T::Output {
1299+
&(**self)[index]
13101300
}
13111301
}
13121302

1313-
impl_index!(usize, A::Item);
1314-
impl_index!(ops::Range<usize>, [A::Item]);
1315-
impl_index!(ops::RangeFrom<usize>, [A::Item]);
1316-
impl_index!(ops::RangeTo<usize>, [A::Item]);
1317-
impl_index!(ops::RangeFull, [A::Item]);
1303+
impl<A: Array, T: SliceIndex<[A::Item]>> ops::IndexMut<T> for SmallVec<A> {
1304+
fn index_mut(&mut self, index: T) -> &mut T::Output {
1305+
&mut (&mut **self)[index]
1306+
}
1307+
}
13181308

13191309
impl<A: Array> ExtendFromSlice<A::Item> for SmallVec<A> where A::Item: Copy {
13201310
fn extend_from_slice(&mut self, other: &[A::Item]) {

0 commit comments

Comments
 (0)