【发布时间】:2015-02-12 05:52:18
【问题描述】:
Rust 切片目前不支持某些迭代器方法,即 take_while。为切片实现 take_while 的最佳方法是什么?
const STRHELLO:&'static[u8] = b"HHHello";
fn main() {
let subslice:&[u8] = STRHELLO.iter().take_while(|c|(**c=='H' as u8)).collect();
println!("Expecting: {}, Got {}",STRHELLO.slice_to(3),subslice);
assert!(subslice==STRHELLO.slice_to(3));
}
导致错误:
<anon>:6:74: 6:83 error: the trait `core::iter::FromIterator<&u8>` is not implemented for the type `&[u8]`
围栏中的这段代码: http://is.gd/1xkcUa
【问题讨论】: