Skip to content

Latest commit

 

History

History
51 lines (45 loc) · 1.63 KB

LEARNINGS.md

File metadata and controls

51 lines (45 loc) · 1.63 KB
struct Foo {
  a: Option<i64>,
  b: Option<i64>,
}
...
let foo = Foo {
  a: 1,
  b: 2,
}

// This is fine
let a = foo.a;
let b = foo.b;

// ERROR - use after move on second line.
// let a = foo.a.unwrap();
// let b = foo.b.unwrap(); // ERROR

This is fine because a copy of foo happens. But, this breaks if in the let a line, you call a method that takes ownership of foo e.g., .unwrap().

TODOs

64 | let tags = fields.tags.unwrap(); | ^^^^^^^^^^^ move occurs because fields.tags has type std::option::Option<std::vec ::Vec<std::string::String>>, which does not implement the Copy trait | help: consider borrowing the Option's content | 64 | let tags = fields.tags.as_ref().unwrap(); | +++++++++