Skip to content

Commit 91ac518

Browse files
committed
Use generic implementation of Index
We can use a generic implementation of `core::ops::Index` which gives us all the range impls for free.
1 parent 15a8c20 commit 91ac518

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

secp256k1-sys/src/macros.rs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -89,55 +89,16 @@ macro_rules! impl_array_newtype {
8989
}
9090
}
9191

92-
impl core::ops::Index<usize> for $thing {
93-
type Output = $ty;
92+
impl<I> core::ops::Index<I> for $thing
93+
where
94+
[$ty]: core::ops::Index<I>,
95+
{
96+
type Output = <[$ty] as core::ops::Index<I>>::Output;
9497

9598
#[inline]
96-
fn index(&self, index: usize) -> &$ty {
97-
let &$thing(ref dat) = self;
98-
&dat[index]
99-
}
99+
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
100100
}
101101

102-
impl core::ops::Index<core::ops::Range<usize>> for $thing {
103-
type Output = [$ty];
104-
105-
#[inline]
106-
fn index(&self, index: core::ops::Range<usize>) -> &[$ty] {
107-
let &$thing(ref dat) = self;
108-
&dat[index]
109-
}
110-
}
111-
112-
impl core::ops::Index<core::ops::RangeTo<usize>> for $thing {
113-
type Output = [$ty];
114-
115-
#[inline]
116-
fn index(&self, index: core::ops::RangeTo<usize>) -> &[$ty] {
117-
let &$thing(ref dat) = self;
118-
&dat[index]
119-
}
120-
}
121-
122-
impl core::ops::Index<core::ops::RangeFrom<usize>> for $thing {
123-
type Output = [$ty];
124-
125-
#[inline]
126-
fn index(&self, index: core::ops::RangeFrom<usize>) -> &[$ty] {
127-
let &$thing(ref dat) = self;
128-
&dat[index]
129-
}
130-
}
131-
132-
impl core::ops::Index<core::ops::RangeFull> for $thing {
133-
type Output = [$ty];
134-
135-
#[inline]
136-
fn index(&self, _: core::ops::RangeFull) -> &[$ty] {
137-
let &$thing(ref dat) = self;
138-
&dat[..]
139-
}
140-
}
141102
impl $crate::CPtr for $thing {
142103
type Target = $ty;
143104
fn as_c_ptr(&self) -> *const Self::Target {

0 commit comments

Comments
 (0)