本文簡要介紹rust語言中 std::slice::Iter.as_slice
的用法。
用法
pub fn as_slice(&self) -> &'a [T]
將基礎數據視為原始數據的子切片。
這與原始切片具有相同的生命周期,因此迭代器可以在它存在時繼續使用。
例子
基本用法:
// First, we declare a type which has the `iter` method to get the `Iter`
// struct (`&[usize]` here):
let slice = &[1, 2, 3];
// Then, we get the iterator:
let mut iter = slice.iter();
// So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
println!("{:?}", iter.as_slice());
// Next, we move to the second element of the slice:
iter.next();
// Now `as_slice` returns "[2, 3]":
println!("{:?}", iter.as_slice());
相關用法
- Rust Iter.as_path用法及代碼示例
- Rust Iterator.skip_while用法及代碼示例
- Rust Iterator.max_by_key用法及代碼示例
- Rust Iterator.is_sorted用法及代碼示例
- Rust Iterator.cmp用法及代碼示例
- Rust Iterator.is_partitioned用法及代碼示例
- Rust Iterator.intersperse用法及代碼示例
- Rust Iterator.scan用法及代碼示例
- Rust Iterator.min用法及代碼示例
- Rust Iterator.find_map用法及代碼示例
- Rust Iterator.peekable用法及代碼示例
- Rust Iterator.rev用法及代碼示例
- Rust Iterator.product用法及代碼示例
- Rust Iterator.any用法及代碼示例
- Rust Iterator.max用法及代碼示例
- Rust Iterator.by_ref用法及代碼示例
- Rust Iterator.min_by用法及代碼示例
- Rust Iterator.copied用法及代碼示例
- Rust Iterator.inspect用法及代碼示例
- Rust Iterator.min_by_key用法及代碼示例
- Rust Iterator.intersperse_with用法及代碼示例
- Rust Iterator.flat_map用法及代碼示例
- Rust Iterator.ge用法及代碼示例
- Rust Iterator.gt用法及代碼示例
- Rust Iterator.partial_cmp_by用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 std::slice::Iter.as_slice。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。