-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement Versionize for VecDeque #13
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Alexandru Agache <[email protected]>
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, just one small suggestion.
app_version: u16, | ||
) -> VersionizeResult<Self> { | ||
let mut v = VecDeque::new(); | ||
let len: u64 = bincode::deserialize_from(&mut reader) |
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.
nit-ish:
Serialized len()
is usize
: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.len
Let's use the same thing here just in case u64
differs in size from usize
:
let len: u64 = bincode::deserialize_from(&mut reader) | |
let len: usize = bincode::deserialize_from(&mut reader) |
) -> VersionizeResult<()> { | ||
// Serialize in the same fashion as bincode: | ||
// Write len. | ||
bincode::serialize_into(&mut writer, &self.len()) |
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.
Can we rely on the Vec primitive here and just use Into/From instead of duplicating the Vec code:
Docs say: This avoids reallocating where possible, but the conditions for that are strict, and subject to change, and so shouldn't be relied upon unless the Vec came from From<VecDeque> and hasn't been reallocated.
Reason for This PR
Added an implementation of
Versionize
forVecDeque
toprimitives.rs
.License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.
PR Checklist
git commit -s
).unsafe
code is properly documented.CHANGELOG.md
.