ownership
This commit is contained in:
parent
eb5eb41e4a
commit
4c8ea45113
2 changed files with 26 additions and 0 deletions
8
10-ownership/Cargo.toml
Normal file
8
10-ownership/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "ownership"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
18
10-ownership/src/main.rs
Normal file
18
10-ownership/src/main.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
fn main()
|
||||||
|
{
|
||||||
|
println!("Hello, world!");
|
||||||
|
|
||||||
|
let n = 5;
|
||||||
|
let s = String::from("Learning Ownership");
|
||||||
|
take_ownership(s, n);
|
||||||
|
//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);
|
||||||
|
} //calls drop for string, so our_string is gone now
|
Loading…
Add table
Add a link
Reference in a new issue