| 1 |
# Shared Bit-Slice Iteration |
| 2 |
|
| 3 |
This view iterates each bit in the bit-slice by [proxy reference][0]. It is |
| 4 |
created by the [`BitSlice::iter`] method. |
| 5 |
|
| 6 |
## Original |
| 7 |
|
| 8 |
[`slice::Iter`](core::slice::Iter) |
| 9 |
|
| 10 |
## API Differences |
| 11 |
|
| 12 |
While this iterator can manifest `&bool` references, it instead yields the |
| 13 |
`bitvec` [proxy reference][0] for consistency with the [`IterMut`] type. It can |
| 14 |
be converted to yield true references with [`.by_refs()`]. Additionally, because |
| 15 |
it does not yield `&bool`, the [`Iterator::copied`] method does not apply. It |
| 16 |
can be converted to an iterator of `bool` values with [`.by_vals()`]. |
| 17 |
|
| 18 |
## Examples |
| 19 |
|
| 20 |
```rust |
| 21 |
use bitvec::prelude::*; |
| 22 |
|
| 23 |
let bits = bits![0, 1]; |
| 24 |
for bit in bits.iter() { |
| 25 |
# #[cfg(feature = "std")] { |
| 26 |
println!("{}", bit); |
| 27 |
# } |
| 28 |
} |
| 29 |
``` |
| 30 |
|
| 31 |
[`BitSlice::iter`]: crate::slice::BitSlice::iter |
| 32 |
[`IterMut`]: crate::slice::IterMut |
| 33 |
[`Iterator::copied`]: core::iter::Iterator::copied |
| 34 |
[`.by_refs()`]: Self::by_refs |
| 35 |
[`.by_vals()`]: Self::by_vals |
| 36 |
[0]: crate::ptr::BitRef |