26 lines
368 B
Rust
26 lines
368 B
Rust
// $ rustc ownersystem_1.rs
|
|
// $ ./ownersystem_1
|
|
struct Bob {
|
|
n: Vec<i32>
|
|
}
|
|
|
|
impl Bob {
|
|
fn new() -> Bob {
|
|
Bob { n: Vec::new() }
|
|
}
|
|
}
|
|
|
|
fn func_1() {
|
|
let n = Bob::new();
|
|
func_2(n);
|
|
//is now out of scope as func_2 owns n now.
|
|
//println!("{}", bob.n[0]);
|
|
}
|
|
|
|
fn func_2(b: Bob) {
|
|
println!("{}", b.n[0]);
|
|
}
|
|
|
|
fn main() {
|
|
func_1();
|
|
} |