// After iterating through valid names, if there are any bits left over // then return one final value that includes them. This makes `into_iter` // and `from_iter` roundtrip if !self.inner.remaining().is_empty() {
Some(B::from_bits_retain(self.inner.remaining.bits()))
} else {
None
}
}
None => None,
}
}
}
impl<B: 'static> IterNames<B> { // Used by the bitflags macro #[doc(hidden)] pubconstfn __private_const_new(flags: &'static [Flag<B>], source: B, remaining: B) -> Self {
IterNames {
flags,
idx: 0,
remaining,
source,
}
}
/// Get a flags value of any remaining bits that haven't been yielded yet. /// /// Once the iterator has finished, this method can be used to /// check whether or not there are any bits that didn't correspond /// to a contained, defined, named flag remaining. pubfn remaining(&self) -> &B {
&self.remaining
}
}
impl<B: Flags> Iterator for IterNames<B> { type Item = (&'static str, B);
fn next(&mutself) -> Option<Self::Item> { whilelet Some(flag) = self.flags.get(self.idx) { // Short-circuit if our state is empty ifself.remaining.is_empty() { return None;
}
self.idx += 1;
// Skip unnamed flags if flag.name().is_empty() { continue;
}
let bits = flag.value().bits();
// If the flag is set in the original source _and_ it has bits that haven't // been covered by a previous flag yet then yield it. These conditions cover // two cases for multi-bit flags: // // 1. When flags partially overlap, such as `0b00000001` and `0b00000101`, we'll // yield both flags. // 2. When flags fully overlap, such as in convenience flags that are a shorthand for others, // we won't yield both flags. ifself.source.contains(B::from_bits_retain(bits))
&& self.remaining.intersects(B::from_bits_retain(bits))
{ self.remaining.remove(B::from_bits_retain(bits));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.