atsamd_hal/util.rs
1/// Iterate over all bits that are `1`, returning the bit's position.
2/// Shamelessly stolen from [embassy](https://github.com/embassy-rs/embassy/blob/3d1501c02038e5fe6f6d3b72bd18bd7a52595a77/embassy-stm32/src/exti.rs#L67)
3pub struct BitIter(pub u32);
4
5impl Iterator for BitIter {
6 type Item = u32;
7
8 fn next(&mut self) -> Option<Self::Item> {
9 match self.0.trailing_zeros() {
10 32 => None,
11 b => {
12 self.0 &= !(1 << b);
13 Some(b)
14 }
15 }
16 }
17}