From 68c285d97b4470f2ed55540135e832ecdc01bb74 Mon Sep 17 00:00:00 2001 From: roneya Date: Tue, 12 Mar 2024 18:01:16 +0530 Subject: [PATCH 1/3] 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 2436f01e6..aeeb123f9 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 From c478b37a0d9ff5494ee86b0c84fa721594189070 Mon Sep 17 00:00:00 2001 From: roneya Date: Tue, 12 Mar 2024 18:05:37 +0530 Subject: [PATCH 2/3] Signed-off-by: roneya --- en/src/smart-pointers/box.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/en/src/smart-pointers/box.md b/en/src/smart-pointers/box.md index aeeb123f9..c27bc6405 100644 --- a/en/src/smart-pointers/box.md +++ b/en/src/smart-pointers/box.md @@ -4,7 +4,7 @@ ```rust,editable // Make it work fn main() { - let b = Box::new(5); + // Create a new box `b` that contains the integer 5 assert_eq!(*b, 5); println!("Success!"); @@ -20,7 +20,7 @@ fn main() { print_boxed_string(b); } -fn print_boxed_string(b : Box<&str>) { +fn print_boxed_string(b : _) { println!("{}", b); } ``` @@ -32,7 +32,7 @@ fn print_boxed_string(b : Box<&str>) { fn main() { let b1 = Box::new(5); let b2 = b1; - assert_eq!(*b2, 5); + assert_eq!(_, 5); println!("Success!"); } From be61b49f9a58c73b66e1c0c077bdaf39c6a50449 Mon Sep 17 00:00:00 2001 From: roneya Date: Tue, 12 Mar 2024 18:12:37 +0530 Subject: [PATCH 3/3] Signed-off-by: roneya --- en/src/smart-pointers/box.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/en/src/smart-pointers/box.md b/en/src/smart-pointers/box.md index c27bc6405..d0928f216 100644 --- a/en/src/smart-pointers/box.md +++ b/en/src/smart-pointers/box.md @@ -38,4 +38,15 @@ fn main() { } ``` +4. 🌟 +```rust,editable + +// Make it work +fn main() { + // Create a box `b` with an array [1, 2, 3, 4, 5] + // Print each integer in `b` +} +``` + + > 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