Skip to content

Commit

Permalink
Implement FromIterator<T> for BitVec<_, T>, per #83
Browse files Browse the repository at this point in the history
  • Loading branch information
myrrlyn committed Oct 17, 2020
1 parent c0b34a2 commit d5e9961
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/vec/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ where
}
}

/** Collect a sequence of memory elements into a bit-vector.
This is a short-hand for, and implemented as, `iter.collect::<Vec<_>>().into()`.
This is not a standard-library API, and was added for [Issue #83].
[Issue #83]: https://github.com/myrrlyn/bitvec/issues/83
**/
impl<O, T> FromIterator<T> for BitVec<O, T>
where
O: BitOrder,
T: BitRegister + BitStore,
{
#[inline]
fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T> {
iter.into_iter().collect::<Vec<_>>().pipe(Self::from_vec)
}
}

impl<'a, O, T> FromIterator<&'a T> for BitVec<O, T>
where
O: BitOrder,
T: BitRegister + BitStore,
{
#[inline]
fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = &'a T> {
iter.into_iter().copied().collect()
}
}

impl<O, T> IntoIterator for BitVec<O, T>
where
O: BitOrder,
Expand Down

0 comments on commit d5e9961

Please sign in to comment.