如何改写接下来拥有这一切在同一行,在函数签名:
fn process(tup: &mut (u32,u32,&mut image::Luma<u8>)) {
let &mut (x,y, _) = tup;
let ref mut pixel = *tup.2;
我得到尽可能:
fn process(&mut (x,y, ref mut pixel): &mut (u32,u32,&mut image::Luma<u8>)) {
但是这并不完全等效,因为我不再是可以这样做:
*pixel = image::Luma([i as u8]);
里面的功能,我可以做的,当我不得不临时tup
结合。
与失败:
src\main.rs:43:14: 43:36 note: expected type `&mut image::Luma<u8>`
src\main.rs:43:14: 43:36 note: found type `image::Luma<u8>`
我也尝试:
process(&mut (x, y, pixel): &mut (u32,u32,&mut image::Luma<u8>))
但这种失败:
src\main.rs:23:12: 23:29 error: cannot move out of borrowed content [E0507]
src\main.rs:23 fn process(&mut (x,y, pixel): &mut (u32,u32,&mut image::Luma<u8>)) {
^~~~~~~~~~~~~~~~~
src\main.rs:23 fn process(&mut (x,y, pixel): &mut (u32,u32,&mut image::Luma<u8>)) {
^~~~~
基本上,我需要的是模式,可以从借解构参考借来值。