Puzzle 21Tying a Gordian Knot
 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


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


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.