Fixed code typo.

pull/789/head
Rustln 3 years ago committed by GitHub
parent a759eb0b38
commit 272a88687d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -177,7 +177,7 @@ fn main() {
let r = &mut v[..]; let r = &mut v[..];
let (a, b) = r.split_at_mut(3); let (a, b) = split_at_mut(r, 3);
assert_eq!(a, &mut [1, 2, 3]); assert_eq!(a, &mut [1, 2, 3]);
assert_eq!(b, &mut [4, 5, 6]); assert_eq!(b, &mut [4, 5, 6]);
@ -219,6 +219,17 @@ fn split_at_mut(slice: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
) )
} }
} }
fn main() {
let mut v = vec![1, 2, 3, 4, 5, 6];
let r = &mut v[..];
let (a, b) = split_at_mut(r, 3);
assert_eq!(a, &mut [1, 2, 3]);
assert_eq!(b, &mut [4, 5, 6]);
}
``` ```
相比安全实现,这段代码就显得没那么好理解了,甚至于我们还需要像 C 语言那样,通过指针地址的偏移去控制数组的分割。 相比安全实现,这段代码就显得没那么好理解了,甚至于我们还需要像 C 语言那样,通过指针地址的偏移去控制数组的分割。

Loading…
Cancel
Save