From a45ef26375ac25f7a4009daa63919b6d0c1c92c6 Mon Sep 17 00:00:00 2001 From: Eduard Bopp Date: Mon, 14 Aug 2017 20:53:55 +0200 Subject: [PATCH] Provide safer Abomonation impl for matrix arrays This is more robust than delegating to a slice, which has been removed upstream due to unsafety. Since we can rely on there being no pointer indirection in a GenericArray, we just iterate over the array. --- src/core/matrix_array.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/matrix_array.rs b/src/core/matrix_array.rs index c344a3a3..86544ec0 100644 --- a/src/core/matrix_array.rs +++ b/src/core/matrix_array.rs @@ -312,14 +312,26 @@ impl Abomonation for MatrixArray N: Abomonation { unsafe fn entomb(&self, writer: &mut Vec) { - self.data.as_slice().entomb(writer) + for element in self.data.as_slice() { + element.entomb(writer); + } } unsafe fn embalm(&mut self) { - self.data.as_slice().embalm() + for element in self.data.as_mut_slice() { + element.embalm(); + } } - unsafe fn exhume<'a, 'b>(&'a mut self, bytes: &'b mut [u8]) -> Option<&'b mut [u8]> { - self.data.as_slice().exhume(bytes) + unsafe fn exhume<'a, 'b>(&'a mut self, mut bytes: &'b mut [u8]) -> Option<&'b mut [u8]> { + for element in self.data.as_mut_slice() { + let temp = bytes; + bytes = if let Some(remainder) = element.exhume(temp) { + remainder + } else { + return None; + } + } + Some(bytes) } }