Theory and Design of PL (CS 538)
March 23, 2020
Result is a monad!? unwraps value if Ok, or returns from function if ErrCopy trait
Clone trait provides .clone() to do deep copylet s = String::from("foo");
let t = s.clone();
// can use both s and t
println!("s = {}, t = {}", s, t);Copy: assignment copies data, no heap dataClone: make explicit copy by calling .clone()Result: avoid memory leaks in Rust
mem::drop
MyStruct1
foo, then bar, then “wrapper”MyStruct2
baz, then “wrapper”MyEnum1
foo OR bar, then “wrapper”MyEnum2
baz, then “wrapper”Option::take(), …