Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
- [Challenge 59](./challenges/challenge-59.md)
- [Challenge 60](./challenges/challenge-60.md)
- [Challenge 61](./challenges/challenge-61.md)
- [Challenge 62](./challenges/challenge-62.md)
- [Resources](./resources.md)
4 changes: 3 additions & 1 deletion src/challenges/challenge-60.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ If the caller ignores it, the compiler will issue a warning. It's great for prev
// Rust Bytes Issue 69: #[must_use] Attribute for Results and Options
#[must_use = "return value of `read` is an `io::Result` which must be handled"]
fn read_data() -> std::io::Result<String> {
//
// ...
Ok("some data".to_string())
}

fn main() {
read_data(); // WARNING: unused `io::Result`
}
```

Try it out yourself using this [Rust Playground Link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=84f3f3dce79ef4519a2849dfedfc112e).
25 changes: 25 additions & 0 deletions src/challenges/challenge-62.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Challenge 62

### Rust Tip: include_str! Macro

`include_str!` is a macro that reads the content of a file at compile time, and embeds it as a `&'static str`

#### When it's useful

For bundling static assets (like configuration files, templates, or small images) directly into your executable.

This avoids runtime file I/O and simplifies deployment as you don't need to ship separate asset files.


```rust
// Rust Bytes Issue 71: include_str! Macro

const GREETING: &str = include_str!("data/greeting.txt");
// Assuming you have a file `data/greeting.txt` in your project root with "Hello, Rust!"

fn main() {
println!("{}", GREETING);
}
```

You can play around with the code on [Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=e49631ea658f2ddb94409c4dcdf9e816).
Loading