Add session_id accessors to Protocol and async Protocol - #167
Conversation
fe565f5 to
059bf60
Compare
|
#61 has already been resolved, closing |
Following up on this as @rustaceanrob previously mentioned this contribution was welcome |
|
Oh I see, it's not available on |
cab79f9 to
24015b9
Compare
|
|
||
| impl SessionId { | ||
| /// Returns the inner 32-byte array. | ||
| pub fn as_bytes(&self) -> &[u8; 32] { |
There was a problem hiding this comment.
[u8; 32] is Copy I think it makes more sense to return an owned [u8; 32]
There was a problem hiding this comment.
Since [u8; 32] is Copy, callers can always do *session_id.as_bytes() when they need an owned array. This avoids unnecessary copies and is convention (I looked at similar usage of as_bytes in bitcoin crate ). To return owned data conventionally to_bytes is used which consumes self.
There was a problem hiding this comment.
At each callsite you've de-referenced it for use, which is some indication to me at least that callers will almost always want an owned version. In the case of primitives like u64, copying is almost always faster than a borrow. I can't imagine this copy would be very costly either. @nyonson do you have any opinion on this?
There was a problem hiding this comment.
I can add to_bytes to return owned [u8; 32] similar to bip32::ChainCode ?
There was a problem hiding this comment.
I like where you have landed in 7804349, lines up with the C-CONV rule in the rust api guidelines which I wanna follow unless we have a real good reason not to.
ce49a25 to
7804349
Compare
- also modify test to verify matching BIP324 session IDs
7804349 to
f874bc9
Compare
|
cc @nyonson for review and merge |
|
ACK f874bc9 |
Add Protocol::session_id() to sync and async
ProtocolUpdate round trip tests to verify both peers derive the same session ID
Fixes #61