Merge rust-bitcoin/rust-bitcoin#733: Super-trivial: Implement `FusedIterator` for `Instructions`
04a8f89f05
Implement `FusedIterator` for `Instructions` (Martin Habovstiak) Pull request description: `Instructions` guarantee to return `None` from empty iterator so we should signal this in type system so that the code can be optimized better. This also adds a test to make sure this property holds. ACKs for top commit: sanket1729: utACK04a8f89f05
. Any special reasons for doing this? RCasatta: ACK04a8f89f05
Tree-SHA512: 3c6284e97e3bdd28ac5e948e3e9946eb8aa285cba753a6a0bdcbf971ebceab6d93c206d284128c232531b3de5996ece91187e4369d88bdfe6c531b4b7f787dd8
This commit is contained in:
commit
31f0beb8df
|
@ -744,6 +744,8 @@ impl<'a> Iterator for Instructions<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> ::core::iter::FusedIterator for Instructions<'a> {}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
/// Creates a new empty script
|
/// Creates a new empty script
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
@ -1388,5 +1390,14 @@ mod test {
|
||||||
assert_eq!(script, ::bincode::deserialize(&bincode).unwrap());
|
assert_eq!(script, ::bincode::deserialize(&bincode).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_instructions_are_fused() {
|
||||||
|
let script = Script::new();
|
||||||
|
let mut instructions = script.instructions();
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue