如何在 Rust 中解构和取消引用元组
How to destructure and derefence tuple in rust
有没有一种方法可以通过在解构元组时在同一行取消引用 foo
和 bar
来简化下面的代码?
let a = "a";
let b = "b";
let c = (&a, &b);
// Can we dereference here?
let (foo, bar) = c;
let foo_loc = *foo;
let bar_loc = *bar;
println!("{}", foo_loc);
println!("{}", bar_loc);
您可以模式匹配参考资料:
fn main() {
let a = "a";
let b = "b";
let c = (&a, &b);
let (&foo, &bar) = c;
println!("{}", foo);
println!("{}", bar);
}
有没有一种方法可以通过在解构元组时在同一行取消引用 foo
和 bar
来简化下面的代码?
let a = "a";
let b = "b";
let c = (&a, &b);
// Can we dereference here?
let (foo, bar) = c;
let foo_loc = *foo;
let bar_loc = *bar;
println!("{}", foo_loc);
println!("{}", bar_loc);
您可以模式匹配参考资料:
fn main() {
let a = "a";
let b = "b";
let c = (&a, &b);
let (&foo, &bar) = c;
println!("{}", foo);
println!("{}", bar);
}