Files
rust-by-practice/en/src/smart-pointers/box.md
2024-03-12 18:01:16 +05:30

622 B

Box

  1. 🌟
// Make it work
fn main() {
    let b = Box::new(5);
    assert_eq!(*b, 5);

    println!("Success!");
}
  1. 🌟

// Make it work
fn main() {
    let b = Box::new("Hello");
    print_boxed_string(b);
}

fn print_boxed_string(b : Box<&str>) {
    println!("{}", b);
}
  1. 🌟

// Make it work
fn main() {
    let b1 = Box::new(5);
    let b2 = b1;
    assert_eq!(*b2, 5);

    println!("Success!");
}

You can find the solutions here(under the solutions path), but only use it when you need it