This is an archive of the discontinued Mercurial Phabricator instance.

rust: use the bytes-cast crate to parse persistent nodemaps
ClosedPublic

Authored by SimonSapin on Jan 15 2021, 10:12 AM.

Details

Summary

This crate casts pointers to custom structs, with compile-time safety checks,
for easy and efficient binary data parsing.

See https://crates.io/crates/bytes-cast and
https://docs.rs/bytes-cast/0.1.0/bytes_cast/

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

SimonSapin created this revision.Jan 15 2021, 10:12 AM
Alphare added inline comments.
rust/hg-core/src/revlog/nodemap.rs
223–224

This comment is now obsolete.

225

Could that be kept as the following and reused later?

rust
pub const BLOCK_SIZE: usize = size_of::<Block>;
386

If you're not going to use a constant (as per my comment above), use size_of as mem is already imported.

612–616

I'd use expect to explain better why this cannot happen.

SimonSapin updated this revision to Diff 25109.Jan 18 2021, 9:22 AM
Alphare accepted this revision.Jan 22 2021, 8:35 AM
pulkit accepted this revision.Jan 26 2021, 3:04 PM
This revision is now accepted and ready to land.Jan 26 2021, 3:04 PM