-
Notifications
You must be signed in to change notification settings - Fork 159
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
Remove a bajillion manual serde implementations #433
Conversation
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 awesome that this library works now, my issue with this is what the code gets expanded to, I can barely read the expanded code after these changes, which is a huge disadvantage in itself and the expanded code is less concise. I do love how it makes the code more readable, but if it means we can't expand to view macro usage, it's a disadvantage.
Can other try cargo expanding themselves to see if they get same issue? I can't reproduce anywhere but here
So changed my mind on this (especially with cargo expand issue being resolved). If someone could also make a thorough pass to make sure of the field ordering and no bytes are serialized without tagging them to be serialized as byte string, that would be great! Definitely with this now we have to be very careful of looking at field ordering to match go impl's but in the long run it should be easier. I also didn't know about the serde_repr derives, definitely much cleaner to use this and the tuple serialize macro (even if a bit more unreadable expanded code, that doesn't matter much) Also closes #185 (very outdated and was created at very start of serde usage) |
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!
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.
LGTM. This is amazing.
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.
Assuming you've decided to keep the randomness wrapper struct. I do believe it makes it much less ergonomic if you have to interact with the wrapper type when unnecessary because the wrapper is only used for deserialization, and no custom functionality is needed, but can always switch later if it becomes annoying I guess
@@ -10,7 +10,7 @@ use serde_bytes::ByteBuf; | |||
pub struct BytesSer<'a>(#[serde(with = "serde_bytes")] pub &'a [u8]); | |||
|
|||
/// Wrapper for deserializing dynamic sized Bytes. | |||
#[derive(Deserialize, Serialize)] | |||
#[derive(Deserialize)] |
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.
optional: to include Serialize on these deserialize types
It's nice to have it symmetric if you need to use one type for serializing and deserializing (no actual examples in code rn but can be useful to move values instead of serializing a reference to them).
5d4a2ef
to
9ce0cfc
Compare
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.
new changes lgtm
This PR adds
serde_tuple
andserde_repr
dependencies in order to remove by far most of our manualSerialize
/Deserialize
implementations.BlockHeader
is the main exception to this because for whatever reasonserde_tuple
andderive_builder
don't seem to work well together.Other minor related changes:
types/src/sector/serde.rs
toserde_tests.rs
because after removing theSerialize
/Deserialize
implementations, the tests were all that was leftbitvec_serde::{serialize, deserialize}
method in order to be used as#[serde(with = "bitvec_serde")]
elsewhereRandomness
type alias into a proper wrapper struct that correctly handles serializationRemove theByte32De
andBytesDe
types as they're no longer neededextern crate serde;
in a couple places as workaround for a compiler bug