Is it possible to unborrow a mutable reference in rust?

  • A+
Category:Languages

Here is an example

#[derive(Debug)] struct Point {     x: Vec<i32>,     y: i32, }  let mut p = Point { x: vec![1], y: 7 };  // borrow out mutable reference p to a and b let Point { x: a, y: b } = &mut p;  // mutate a a.push(2);  // how do I get p back? println!("{:?}", p); 

Is there a way to unborrow the reference without creating a new block or abstract into function?

 


Use Rust 2018.

In Rust 2018, which has NLL, your example is valid.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: