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 live online training, plus books, videos, and digital content from nearly 200 publishers.