我有一个数组
let buffer: &[u8] = &[0; 40000];
但是当我想像这样进行映射:
*buffer.map( |x| 0xff);
我遇到了以下错误:
error[E0599]: no method named `map` found for type `&[u8]` in the current scope
--> src/bin/save_png.rs:12:13
|
12 | *buffer.map( |x| 0xff); //.map(|x| 0xff);
| ^^^
|
= note: the method `map` exists but the following trait bounds were not satisfied:
`&mut &[u8] : std::iter::Iterator`
`&mut [u8] : std::iter::Iterator`
我尝试了几种方法使元素可变,但是我得不到正确的语法。有经验的人可以帮忙吗?我正在尝试处理png图像缓冲。
Vec
吗? - User.collect()
不知道输入的长度,在 Rust 中数组是固定长度的。你可以查看所有可以收集的东西,通过查看哪些实现了FromIterator
接口:https://doc.rust-lang.org/std/iter/trait.FromIterator.html#implementors - Kevin M Granger