本文簡要介紹rust語言中 array.split_array_ref 的用法。
用法
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])在索引處將一個數組引用一分為二。
第一個將包含來自[0, M) 的所有索引(不包括索引M 本身),第二個將包含來自[M, N) 的所有索引(不包括索引N 本身)。
Panics
如果 M > N 出現Panics。
例子
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}
{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}相關用法
- Rust array.split_array_mut用法及代碼示例
- Rust array.map用法及代碼示例
- Rust array.zip用法及代碼示例
- Rust array.each_mut用法及代碼示例
- Rust array.each_ref用法及代碼示例
- Rust array用法及代碼示例
- Rust args用法及代碼示例
- Rust args_os用法及代碼示例
- Rust assert_ne用法及代碼示例
- Rust assert_matches用法及代碼示例
- Rust addr_of_mut用法及代碼示例
- Rust alloc_zeroed用法及代碼示例
- Rust align_of用法及代碼示例
- Rust always_abort用法及代碼示例
- Rust assert_eq用法及代碼示例
- Rust available_parallelism用法及代碼示例
- Rust addr_of用法及代碼示例
- Rust abort用法及代碼示例
- Rust align_of_val用法及代碼示例
- Rust assert用法及代碼示例
- Rust alloc用法及代碼示例
- Rust align_of_val_raw用法及代碼示例
- Rust UdpSocket.set_multicast_loop_v6用法及代碼示例
- Rust i64.overflowing_add_unsigned用法及代碼示例
- Rust Box.downcast用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 array.split_array_ref。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
