diff --git a/.travis.yml b/.travis.yml index ee744e1..2dc4702 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: rust rust: - - 1.20.0 + - 1.36.0 - nightly - beta - stable diff --git a/lib.rs b/lib.rs index cedf2bd..4036547 100644 --- a/lib.rs +++ b/lib.rs @@ -60,6 +60,7 @@ use std::mem::ManuallyDrop; use std::ops; use std::ptr; use std::slice; +use std::slice::SliceIndex; #[cfg(feature = "std")] use std::io; #[cfg(feature = "serde")] @@ -1291,30 +1292,19 @@ impl From for SmallVec { } } -macro_rules! impl_index { - ($index_type: ty, $output_type: ty) => { - impl ops::Index<$index_type> for SmallVec { - type Output = $output_type; - #[inline] - fn index(&self, index: $index_type) -> &$output_type { - &(&**self)[index] - } - } +impl> ops::Index for SmallVec { + type Output = I::Output; - impl ops::IndexMut<$index_type> for SmallVec { - #[inline] - fn index_mut(&mut self, index: $index_type) -> &mut $output_type { - &mut (&mut **self)[index] - } - } + fn index(&self, index: I) -> &I::Output { + &(**self)[index] } } -impl_index!(usize, A::Item); -impl_index!(ops::Range, [A::Item]); -impl_index!(ops::RangeFrom, [A::Item]); -impl_index!(ops::RangeTo, [A::Item]); -impl_index!(ops::RangeFull, [A::Item]); +impl> ops::IndexMut for SmallVec { + fn index_mut(&mut self, index: I) -> &mut I::Output { + &mut (&mut **self)[index] + } +} impl ExtendFromSlice for SmallVec where A::Item: Copy { fn extend_from_slice(&mut self, other: &[A::Item]) {