Update implementation code of `split_at_mut`

pull/215/head
Youngsuk Kim 5 years ago committed by Alexis Beingessner
parent 0559f276a3
commit 1e1dd962c7

@ -66,13 +66,15 @@ the implementation requires some unsafety:
# impl<T> FakeSlice<T> { # impl<T> FakeSlice<T> {
# fn len(&self) -> usize { unimplemented!() } # fn len(&self) -> usize { unimplemented!() }
# fn as_mut_ptr(&mut self) -> *mut T { unimplemented!() } # fn as_mut_ptr(&mut self) -> *mut T { unimplemented!() }
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { pub fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
let len = self.len(); let len = self.len();
let ptr = self.as_mut_ptr(); let ptr = self.as_mut_ptr();
assert!(mid <= len);
unsafe { unsafe {
assert!(mid <= len);
(from_raw_parts_mut(ptr, mid), (from_raw_parts_mut(ptr, mid),
from_raw_parts_mut(ptr.offset(mid as isize), len - mid)) from_raw_parts_mut(ptr.add(mid), len - mid))
} }
} }
# } # }

Loading…
Cancel
Save