-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add equals method to protocol objects in WASM bindings #64
Add equals method to protocol objects in WASM bindings #64
Conversation
ef84faf
to
23fca8e
Compare
macro_rules! generate_from_bytes { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
#[wasm_bindgen(js_name = "fromBytes")] | ||
pub fn from_bytes(bytes: &[u8]) -> Result<$struct_name, Error> { | ||
from_bytes(bytes).map(Self) | ||
} | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! It's not too abstract and is nice encapsulation of boilerplate for bindings.
generate_equals!(MessageKit); | ||
generate_from_bytes!(MessageKit); | ||
generate_to_bytes!(MessageKit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great - can is be abstracted farther or does that cross some kind of line? 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could put these into generate_common_methods!
but I didn't find it as useful.
|
||
#[wasm_bindgen(js_name = toBytes)] | ||
pub fn to_bytes(&self) -> Box<[u8]> { | ||
to_bytes(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original to_bytes()
here uses self
. The macro uses &self
. Why the discrepancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a typo. I think normally clippy
would have caught this, but &self
was inside the macro. This isn't an issue since the resulting &&self
would be coerced to just &self
, but it's worth fixing.
}; | ||
} | ||
|
||
macro_rules! generate_to_string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎸 - nice split of the macros.
23fca8e
to
0917370
Compare
Type of PR:
Required reviews:
What this does:
equals
method to WASM bindingsIssues fixed/closed:
PartialEq
andEq
for WASM structs in bindings #56Why it's needed:
Notes for reviewers:
ferveo
versiongenerate_to_bytes
may only replace someto_bytes
methods and so will require more work / another macro to be introduced.nucypher