First published at 14:26 UTC on January 12th, 2018.
MORE
Today were going to go over simple data types
and ownership with functions.
https://play.rust-lang.org/
https://doc.rust-lang.org/book/second-edition/ch04-01-what-is-ownership.html
let x = 5;
let y = x;
println!("x = {}, y = {}", x, y);
because x is a simple date type its stored on the stack.
It just clones the data of x into y, leaving x still as
a valid variable.
What that means is the code below does the exact same thing as above.
let x = 5;
let y = x.clone();
rust also has a copy type that can be placed on data on the stack. We'll go
over it more indepth in chapter 10.
If a type has the Copy trait, an older variable is still usable after assignment.
Rust won’t let us annotate a type with the Copy trait if the type, or any of its
parts, has implemented the Drop trait. If the type needs something special to happen
when the value goes out of scope and we add the Copy annotation to that type, we’ll
get a compile time error.
All the integer types, like u32.
The boolean type, bool, with values true and false.
The character type, char.
All the floating point types, like f64.
Tuples, but only if they contain types that are also Copy. (i32, i32) is Copy, but (i32, String) is not.
LESS