forked from M-Labs/nalgebra
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.
This commit is contained in:
parent
66f491ffa7
commit
a45ef26375
@ -312,14 +312,26 @@ impl<N, R, C> Abomonation for MatrixArray<N, R, C>
|
|||||||
N: Abomonation
|
N: Abomonation
|
||||||
{
|
{
|
||||||
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
unsafe fn entomb(&self, writer: &mut Vec<u8>) {
|
||||||
self.data.as_slice().entomb(writer)
|
for element in self.data.as_slice() {
|
||||||
|
element.entomb(writer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn embalm(&mut self) {
|
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]> {
|
unsafe fn exhume<'a, 'b>(&'a mut self, mut bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
|
||||||
self.data.as_slice().exhume(bytes)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user