Drop and move behavior
This commit is contained in:
parent
823ec0ad00
commit
bd260f1769
18
src/main.rs
18
src/main.rs
@ -10,14 +10,28 @@ impl Vector3 {
|
||||
}
|
||||
}
|
||||
|
||||
fn print(vec: Vector3) {
|
||||
fn print(vec: Vector3) -> Vector3 {
|
||||
println!("Vector3( x = {}, y = {}, z = {})", vec.x, vec.y, vec.z);
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
impl Drop for Vector3 {
|
||||
fn drop(&mut self) {
|
||||
println!("Vector3 was dropped!");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut vec = Vector3::new(1.0, 0.0, 0.0);
|
||||
|
||||
print(vec);
|
||||
/*
|
||||
println!("Calling print");
|
||||
let vec2 = print(vec);
|
||||
println!("Calling print returned");
|
||||
*/
|
||||
|
||||
let vec2 = vec;
|
||||
|
||||
vec.y = 2.0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user