diff rust/hg-core/src/revlog/revlog.rs @ 46390:0800aa42bb4c

rust: use the bytes-cast crate to parse persistent nodemaps 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/ Differential Revision: https://phab.mercurial-scm.org/D9788
author Simon Sapin <simon.sapin@octobus.net>
date Fri, 15 Jan 2021 16:11:54 +0100
parents 8a4914397d02
children 645ee7225fab
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/revlog.rs	Mon Jan 25 19:03:27 2021 -0500
+++ b/rust/hg-core/src/revlog/revlog.rs	Fri Jan 15 16:11:54 2021 +0100
@@ -29,6 +29,12 @@
     UnknowDataFormat(u8),
 }
 
+impl From<bytes_cast::FromBytesError> for RevlogError {
+    fn from(_: bytes_cast::FromBytesError) -> Self {
+        RevlogError::Corrupted
+    }
+}
+
 /// Read only implementation of revlog.
 pub struct Revlog {
     /// When index and data are not interleaved: bytes of the revlog index.