sdk/rust: Add `Body::with_payload`

Add the `Body::with_payload` method, which can be used to change the
type of the payload for a `Body`.  This is useful when parsing the
payload needs to be deferred until after the body is parsed.
This commit is contained in:
Chirantan Ekbote 2022-12-15 19:41:26 +09:00 committed by Chirantan Ekbote
parent 4ea369d7a9
commit 0dbeeec3d4
1 changed files with 15 additions and 0 deletions

View File

@ -218,6 +218,21 @@ impl Header {
}
}
impl<P> Body<P> {
/// Replace the payload of the body. Useful when parsing the payload needs to be delayed.
pub fn with_payload<U>(self, p: U) -> Body<U> {
Body {
timestamp: self.timestamp,
nonce: self.nonce,
emitter_chain: self.emitter_chain,
emitter_address: self.emitter_address,
sequence: self.sequence,
consistency_level: self.consistency_level,
payload: p,
}
}
}
impl<P: Serialize> Body<P> {
/// Body Digest Components.
///