rustup. (Collection trait is gone.)
This commit is contained in:
parent
b3b742b3ab
commit
beace646d0
42
src/ec.rs
42
src/ec.rs
|
@ -63,35 +63,20 @@ mod ec_tests {
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//{{{ Interleave support
|
//{{{ Interleave support
|
||||||
|
|
||||||
// TODO Make Vec implements ImmutableVector, or &[T] implements Index.
|
// TODO Make &[T] implement Deref<[T]>
|
||||||
trait InterleaveSupport<T> {
|
trait XDeref<Sized? T> {
|
||||||
/// Equivalent to
|
fn deref2(&self) -> &T;
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// if i < self.len() {
|
|
||||||
/// v.push(self[i]);
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// This trait exists solely because `Vec<T>` does not implement
|
|
||||||
/// ImmutableVector, or `&[T]` does not implement Index. This trait can be
|
|
||||||
/// deprecated once either of above are implemented.
|
|
||||||
fn push_item_to(&self, i: uint, v: &mut Vec<T>);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> InterleaveSupport<T> for Vec<T> {
|
impl<T> XDeref<[T]> for Vec<T> {
|
||||||
fn push_item_to(&self, i: uint, v: &mut Vec<T>) {
|
fn deref2(&self) -> &[T] {
|
||||||
if i < self.len() {
|
self.deref()
|
||||||
v.push(self[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Copy> InterleaveSupport<T> for &'a [T] {
|
impl<'a, Sized? T> XDeref<T> for &'a T {
|
||||||
fn push_item_to(&self, i: uint, v: &mut Vec<T>) {
|
fn deref2(&self) -> &T {
|
||||||
if i < self.len() {
|
*self
|
||||||
v.push(self[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,13 +88,16 @@ impl<'a, T: Copy> InterleaveSupport<T> for &'a [T] {
|
||||||
/// The longest slice must be at the last of `blocks`, and `blocks` must not be
|
/// The longest slice must be at the last of `blocks`, and `blocks` must not be
|
||||||
/// empty.
|
/// empty.
|
||||||
fn interleave<T: Copy, V>(blocks: &Vec<V>) -> Vec<T>
|
fn interleave<T: Copy, V>(blocks: &Vec<V>) -> Vec<T>
|
||||||
where V: InterleaveSupport<T> + Collection
|
where V: XDeref<[T]>
|
||||||
{
|
{
|
||||||
let last_block_len = blocks.last().unwrap().len();
|
let last_block_len = blocks.last().unwrap().deref2().len();
|
||||||
let mut res = Vec::with_capacity(last_block_len * blocks.len());
|
let mut res = Vec::with_capacity(last_block_len * blocks.len());
|
||||||
for i in range(0, last_block_len) {
|
for i in range(0, last_block_len) {
|
||||||
for t in blocks.iter() {
|
for t in blocks.iter() {
|
||||||
t.push_item_to(i, &mut res);
|
let tref = t.deref2();
|
||||||
|
if i < tref.len() {
|
||||||
|
res.push(tref[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
|
|
Loading…
Reference in a new issue