Skip to content

Commit c6702ce

Browse files
committed
consensus_encoding: Implement Encoder for Option<T>
Add support for optionally encoding some data by implementing `Encoder for Option<T: Encoder>`. Idea from Nick during review. Co-developed-by: Nick Johnson <[email protected]>
1 parent da69bbd commit c6702ce

File tree

1 file changed

+16
-0
lines changed
  • consensus_encoding/src/encode

1 file changed

+16
-0
lines changed

consensus_encoding/src/encode/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,19 @@ where
122122
}
123123
Ok(())
124124
}
125+
126+
impl<T: Encoder> Encoder for Option<T> {
127+
fn current_chunk(&self) -> Option<&[u8]> {
128+
match self {
129+
Some(encoder) => encoder.current_chunk(),
130+
None => None,
131+
}
132+
}
133+
134+
fn advance(&mut self) -> bool {
135+
match self {
136+
Some(encoder) => encoder.advance(),
137+
None => false,
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)