Puzzle 21Tying a Gordian Knot
 #​[​derive​(Debug)]
 struct​ Parser<'a> {
  body: String,
  subtext : &'a str,
 }
 
 fn​ ​main​() {
 let​ ​mut​ document = Parser {
  body: ​"Hello"​​.to_string​(),
  subtext: ​""
  };
  document.subtext = &document.body;
 
 let​ b = document;
  println!(​"{:?}"​, b);
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program will fail to compile with the following message:

 error[E0505]: cannot move out of `document` because it is borrowed
  --> ...

Get Rust Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.