2023-05-07 03:16:37 +03:00
|
|
|
fn main()
|
|
|
|
{
|
|
|
|
println!("Hello, world!");
|
|
|
|
|
|
|
|
let n = 5;
|
|
|
|
let s = String::from("Learning Ownership");
|
2023-05-07 03:47:23 +03:00
|
|
|
take_ownership(s, n);//s is moved n is copied
|
2023-05-07 03:16:37 +03:00
|
|
|
//println!("{}", s); It's gone
|
|
|
|
println!("Not Transferred, Just Copied = {}", n);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn take_ownership(our_string:String, our_number:i32)
|
|
|
|
{
|
|
|
|
//ownership is transferred for string
|
|
|
|
println!("I got your String = {}", our_string);
|
|
|
|
println!("I got your Number = {}", our_number);
|
2023-05-07 03:47:23 +03:00
|
|
|
} //calls "drop" for string, so our_string is gone now
|