From 68c285d97b4470f2ed55540135e832ecdc01bb74 Mon Sep 17 00:00:00 2001 From: roneya Date: Tue, 12 Mar 2024 18:01:16 +0530 Subject: [PATCH] box practice questions --- en/src/smart-pointers/box.md | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/en/src/smart-pointers/box.md b/en/src/smart-pointers/box.md index 2436f01..aeeb123 100644 --- a/en/src/smart-pointers/box.md +++ b/en/src/smart-pointers/box.md @@ -1 +1,41 @@ # Box + +1. 🌟 +```rust,editable +// Make it work +fn main() { + let b = Box::new(5); + assert_eq!(*b, 5); + + println!("Success!"); +} +``` + +2. 🌟 +```rust,editable + +// Make it work +fn main() { + let b = Box::new("Hello"); + print_boxed_string(b); +} + +fn print_boxed_string(b : Box<&str>) { + println!("{}", b); +} +``` + +3. 🌟 +```rust,editable + +// 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](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it