Rust Smart pointers

let us look at Rust smart pointers examples. Smart pointers like Box help save the heap information of an object.

fn main() {
   let y = 7;

   let z = Box::new(y);

   println!("{}",7==y);
   println!("{}",7==*z);

}

The code above is compiled using the below command.

apples-MacBook-Air:iterators bhagvan.kommadi$ rustc smartpointers.rs

The output will be as below:

apples-MacBook-Air:smartpointers bhagvan.kommadi$ ./smartpointers
true
true

Leave a comment