├── .github
└── workflows
│ └── mdbook.yml
├── .gitignore
├── LICENSE
├── README.md
├── assets
└── lets-get-rusty-learning-guide.png
├── book.toml
├── src
├── SUMMARY.md
├── advanced
│ ├── async-await-traits.md
│ ├── attribute-like.md
│ ├── calling-unsafe-functions.md
│ ├── creating-threads.md
│ ├── custom-derive.md
│ ├── declarative-macros.md
│ ├── dereferencing-raw-pointers.md
│ ├── ffi-c-from-rust.md
│ ├── ffi-rust-from-c.md
│ ├── ffi-rust-from-python.md
│ ├── function-like.md
│ ├── implementing-unsafe-traits.md
│ ├── inline-assembly.md
│ ├── intro-to-concurrency.md
│ ├── intro-to-macros.md
│ ├── intro-to-unsafe-rust.md
│ ├── moving-values-into-threads.md
│ ├── mutable-static-variables.md
│ ├── passing-messages-between-threads.md
│ ├── procedural-macros.md
│ ├── send-and-sync-traits.md
│ ├── sharing-states-between-threads.md
│ ├── tokio-streams.md
│ └── tokio-tasks.md
├── beginner
│ ├── basics.md
│ ├── benchmark-tests.md
│ ├── borrowing.md
│ ├── cargo-features.md
│ ├── cargo-workspaces.md
│ ├── comments.md
│ ├── constants-statics-exercises.md
│ ├── constants-statics.md
│ ├── control-flow.md
│ ├── data-types.md
│ ├── documentation.md
│ ├── enums.md
│ ├── external-dependencies.md
│ ├── functions.md
│ ├── hello-world.md
│ ├── implementation-blocks.md
│ ├── integration-tests.md
│ ├── matching.md
│ ├── memory-saftey.md
│ ├── modules.md
│ ├── option.md
│ ├── ownership.md
│ ├── project-structure.md
│ ├── publishing-your-package.md
│ ├── result.md
│ ├── setup.md
│ ├── slices.md
│ ├── strings.md
│ ├── structs.md
│ ├── tuple-structs.md
│ ├── unit-tests.md
│ ├── variables.md
│ └── vectors.md
├── curriculum
│ ├── accelerator.html
│ ├── favicon.png
│ ├── index.html
│ └── lgr_logo.png
├── further-learning
│ ├── api-project.md
│ ├── building-microservices-in-rust.md
│ ├── cli-project.md
│ ├── deep-dive-into-string-in-rust.md
│ ├── mircoservices-project.md
│ ├── rust-based-computer-science.md
│ └── systems-programming-in-rust.md
├── index.md
├── intermediate
│ ├── anyhow.md
│ ├── avoiding-unwrap.md
│ ├── box-smart-pointer.md
│ ├── closures.md
│ ├── combinators.md
│ ├── concrete-lifetimes.md
│ ├── custom-errors.md
│ ├── deref-coercion.md
│ ├── deriving-traits.md
│ ├── error-stack.md
│ ├── function-pointers.md
│ ├── generics-lifetimes.md
│ ├── generics.md
│ ├── iterator-over-collections.md
│ ├── iterator-pattern.md
│ ├── lifetime-elision.md
│ ├── multiple-error-types-exercises.md
│ ├── multiple-error-types.md
│ ├── orphan-rule.md
│ ├── propagating-errors.md
│ ├── rc-smart-pointer.md
│ ├── recoverable-errors.md
│ ├── refcell-smart-pointer.md
│ ├── result-and-option.md
│ ├── supertraits.md
│ ├── thiserror.md
│ ├── trait-bounds.md
│ ├── trait-objects.md
│ ├── traits.md
│ └── unrecoverable-errors.md
├── roadmap
│ ├── favicon.png
│ ├── index.html
│ └── lgr_logo.png
├── start-with-tris
│ ├── favicon.png
│ ├── index.html
│ └── lgr_logo.png
├── start
│ ├── favicon.png
│ ├── index.html
│ └── lgr_logo.png
└── starter-pack
│ ├── curriculum.html
│ ├── favicon.png
│ ├── index.html
│ └── lgr_logo.png
└── theme
├── book.js
├── css
├── chrome.css
├── general.css
├── print.css
└── variables.css
├── favicon.png
├── favicon.svg
├── fonts
├── OPEN-SANS-LICENSE.txt
├── SOURCE-CODE-PRO-LICENSE.txt
├── fonts.css
├── open-sans-v17-all-charsets-300.woff2
├── open-sans-v17-all-charsets-300italic.woff2
├── open-sans-v17-all-charsets-600.woff2
├── open-sans-v17-all-charsets-600italic.woff2
├── open-sans-v17-all-charsets-700.woff2
├── open-sans-v17-all-charsets-700italic.woff2
├── open-sans-v17-all-charsets-800.woff2
├── open-sans-v17-all-charsets-800italic.woff2
├── open-sans-v17-all-charsets-italic.woff2
├── open-sans-v17-all-charsets-regular.woff2
└── source-code-pro-v11-all-charsets-500.woff2
├── head.hbs
├── highlight.css
├── highlight.js
└── index.hbs
/.github/workflows/mdbook.yml:
--------------------------------------------------------------------------------
1 | # Sample workflow for building and deploying a mdBook site to GitHub Pages
2 | #
3 | # To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
4 | #
5 | name: Deploy mdBook site to Pages
6 |
7 | on:
8 | # Runs on pushes targeting the default branch
9 | push:
10 | branches: ["main"]
11 |
12 | # Allows you to run this workflow manually from the Actions tab
13 | workflow_dispatch:
14 |
15 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16 | permissions:
17 | contents: read
18 | pages: write
19 | id-token: write
20 |
21 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
23 | concurrency:
24 | group: "pages"
25 | cancel-in-progress: false
26 |
27 | jobs:
28 | # Build job
29 | build:
30 | runs-on: ubuntu-latest
31 | env:
32 | MDBOOK_VERSION: 0.4.36
33 | steps:
34 | - uses: actions/checkout@v4
35 | - name: Install mdBook
36 | run: |
37 | curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
38 | rustup update
39 | cargo install --version ${MDBOOK_VERSION} mdbook
40 | - name: Setup Pages
41 | id: pages
42 | uses: actions/configure-pages@v4
43 | - name: Build with mdBook
44 | run: mdbook build
45 | - name: Upload artifact
46 | uses: actions/upload-pages-artifact@v3
47 | with:
48 | path: ./book
49 |
50 | # Deployment job
51 | deploy:
52 | environment:
53 | name: github-pages
54 | url: ${{ steps.deployment.outputs.page_url }}
55 | runs-on: ubuntu-latest
56 | needs: build
57 | steps:
58 | - name: Deploy to GitHub Pages
59 | id: deployment
60 | uses: actions/deploy-pages@v4
61 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | debug/
4 | target/
5 |
6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8 | Cargo.lock
9 |
10 | # These are backup files generated by rustfmt
11 | **/*.rs.bk
12 |
13 | # MSVC Windows builds of rustc generate these, which store debugging information
14 | *.pdb
15 |
16 | # Generated by mdBook
17 | book
18 | .DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Let's Get Rusty
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Let's Get Rusty Learning Guide 🦀
2 |
3 | 
4 |
5 | This is a space designed for aspiring Rust developers.
6 |
7 | The curriculum is composed of existing YouTube videos by Let's Get Rusty, organized to guide you step-by-step through your Rust learning journey.
8 |
9 | And to make your learning more interactive, there're exercises covering most of the topics. So, whether you're just starting out or looking to sharpen your skills in Rust, this is the perfect place for you.
10 |
11 | To discuss and/or collaborate with other Rust developers, join our [Discord community](https://discord.com/invite/wTfbkNeZnv)!
12 |
13 | ## Features
14 |
15 | - Tutorial videos by Let's Get Rusty
16 |
17 | - Additional resources
18 |
19 | - Exercises
20 |
21 | - Exercise solutions
22 |
23 | - More user customizations coming soon!
24 |
25 | ## Installation
26 |
27 | ```shell
28 | git clone git@github.com:letsgetrusty/rust-learning-guide.git
29 |
30 | cargo install mdbook
31 |
32 | cd rust-learning-guide && mdbook serve --open
33 | ```
34 |
35 | ## Credits
36 |
37 | - Bogdan himself :)
38 |
39 | - Talented technical writers @ Let's Get Rusty
40 |
41 | - OP open-source community contributors!
42 |
43 | - [The Rust Book](https://github.com/rust-lang/book), [Rust By Example](https://github.com/rust-lang/rust-by-example), [Rust By Practice](https://github.com/sunface/rust-by-practice)
44 |
45 | ## Licenses
46 |
47 | - MIT License
--------------------------------------------------------------------------------
/assets/lets-get-rusty-learning-guide.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/letsgetrusty/learn/8159c9f0eccbd2be97a2ec541266e99b1c3b3cec/assets/lets-get-rusty-learning-guide.png
--------------------------------------------------------------------------------
/book.toml:
--------------------------------------------------------------------------------
1 | [book]
2 | authors = ["letsgetrusty"]
3 | language = "en"
4 | multilingual = false
5 | src = "src"
6 | title = "Let's Get Rusty"
7 |
8 | [output.html]
9 | default-theme = "ayu"
10 | preferred-dark-theme = "ayu"
11 | no-section-label = true
12 |
13 | [output.html.fold]
14 | enable = true
15 | level = 0
16 |
17 | [output.html.playground]
18 | editable = true
19 |
20 | [rust]
21 | edition = "2021"
--------------------------------------------------------------------------------
/src/SUMMARY.md:
--------------------------------------------------------------------------------
1 | # Summary
2 |
3 |
4 | [Let's Get Rusty Learning Guide](index.md)
5 |
6 | # Beginner
7 |
8 | ----
9 |
10 | - [Basics](beginner/setup.md)
11 | - [Setup](beginner/setup.md)
12 | - [Hello World](beginner/hello-world.md)
13 | - [Comments](beginner/comments.md)
14 | - [Variables](beginner/variables.md)
15 | - [Data Types](beginner/data-types.md)
16 | - [Constants & Statics](beginner/constants-statics.md)
17 | - [Functions](beginner/functions.md)
18 | - [Control Flow](beginner/control-flow.md)
19 | - [Memory Safety](beginner/ownership.md)
20 | - [Ownership](beginner/ownership.md)
21 | - [Borrowing](beginner/borrowing.md)
22 | - [Slices](beginner/slices.md)
23 | - [Strings](beginner/strings.md)
24 | - [Custom Data Types](beginner/structs.md)
25 | - [Structs](beginner/structs.md)
26 | - [Implementation Blocks](beginner/implementation-blocks.md)
27 | - [Tuple Structs](beginner/tuple-structs.md)
28 | - [Enums](beginner/enums.md)
29 | - [Matching](beginner/matching.md)
30 | - [Option](beginner/option.md)
31 | - [Result](beginner/result.md)
32 | - [Vectors](beginner/vectors.md)
33 | - [Project Structure](beginner/project-structure.md)
34 | - [Project Structure Overview](beginner/project-structure.md)
35 | - [Modules](beginner/modules.md)
36 | - [External Dependencies](beginner/external-dependencies.md)
37 | - [Publishing Your Package](beginner/publishing-your-package.md)
38 | - [Cargo Features](beginner/cargo-features.md)
39 | - [Cargo Workspaces](beginner/cargo-workspaces.md)
40 | - [Testing](beginner/unit-tests.md)
41 | - [Unit Tests](beginner/unit-tests.md)
42 | - [Integration Tests](beginner/integration-tests.md)
43 | - [Benchmark Tests](beginner/benchmark-tests.md)
44 | - [Documentation](beginner/documentation.md)
45 |
46 | # Intermediate
47 |
48 | ----
49 |
50 | - [Polymorphism](intermediate/generics.md)
51 | - [Generics](intermediate/generics.md)
52 | - [Traits](intermediate/traits.md)
53 | - [Trait Bounds](intermediate/trait-bounds.md)
54 | - [Supertraits](intermediate/supertraits.md)
55 | - [Trait Objects](intermediate/trait-objects.md)
56 | - [Deriving Traits](intermediate/deriving-traits.md)
57 | - [Orphan Rule](intermediate/orphan-rule.md)
58 | - [Advanced Memory Management](intermediate/concrete-lifetimes.md)
59 | - [Concrete Lifetimes](intermediate/concrete-lifetimes.md)
60 | - [Generic Lifetimes](intermediate/generics-lifetimes.md)
61 | - [Lifetime Elision](intermediate/lifetime-elision.md)
62 | - [Box Smart Pointer](intermediate/box-smart-pointer.md)
63 | - [Rc Smart Pointer](intermediate/rc-smart-pointer.md)
64 | - [RefCell Smart Pointer](intermediate/refcell-smart-pointer.md)
65 | - [Deref Coercion](intermediate/deref-coercion.md)
66 | - [Error Handling](intermediate/unrecoverable-errors.md)
67 | - [Unrecoverable Errors](intermediate/unrecoverable-errors.md)
68 | - [Recoverable Errors](intermediate/recoverable-errors.md)
69 | - [Propagating Errors](intermediate/propagating-errors.md)
70 | - [Result and Option](intermediate/result-and-option.md)
71 | - [Multiple Error Types](intermediate/multiple-error-types.md)
72 | - [Advanced Error Handling](intermediate/avoiding-unwrap.md)
73 | - [Avoiding Unwrap](intermediate/avoiding-unwrap.md)
74 | - [Custom Errors](intermediate/custom-errors.md)
75 | - [thiserror](intermediate/thiserror.md)
76 | - [anyhow](intermediate/anyhow.md)
77 | - [error-stack](intermediate/error-stack.md)
78 | - [Functional Programming](intermediate/closures.md)
79 | - [Closures](intermediate/closures.md)
80 | - [Function Pointers](intermediate/function-pointers.md)
81 | - [Iterator Pattern](intermediate/iterator-pattern.md)
82 | - [Iterator over Collections](intermediate/iterator-over-collections.md)
83 | - [Combinators](intermediate/combinators.md)
84 |
85 | # Advanced
86 |
87 | ----
88 |
89 | - [Concurrency](advanced/intro-to-concurrency.md)
90 | - [Intro to Concurrency](advanced/intro-to-concurrency.md)
91 | - [Creating Threads](advanced/creating-threads.md)
92 | - [Moving Values into Threads](advanced/moving-values-into-threads.md)
93 | - [Passing Messages between Threads](advanced/passing-messages-between-threads.md)
94 | - [Sharing States between Threads](advanced/sharing-states-between-threads.md)
95 | - [Send and Sync Traits](advanced/send-and-sync-traits.md)
96 | - [async/.await](advanced/async-await-traits.md)
97 | - [Tokio Tasks](advanced/tokio-tasks.md)
98 | - [Tokio Streams](advanced/tokio-streams.md)
99 | - [Macros](advanced/intro-to-macros.md)
100 | - [Intro to Macros](advanced/intro-to-macros.md)
101 | - [Declarative Macros](advanced/declarative-macros.md)
102 | - [Procedural Macros](advanced/procedural-macros.md)
103 | - [Custom Derive](advanced/custom-derive.md)
104 | - [Attribute Like](advanced/attribute-like.md)
105 | - [Function Like](advanced/function-like.md)
106 | - [Unsafe Rust and FFI](advanced/intro-to-unsafe-rust.md)
107 | - [Intro to Unsafe Rust](advanced/intro-to-unsafe-rust.md)
108 | - [Dereferencing Raw Pointers](advanced/dereferencing-raw-pointers.md)
109 | - [Calling Unsafe Functions](advanced/calling-unsafe-functions.md)
110 | - [Mutable Static Variables](advanced/mutable-static-variables.md)
111 | - [Implementing Unsafe Traits](advanced/implementing-unsafe-traits.md)
112 | - [Inline Assembly](advanced/inline-assembly.md)
113 | - [FFI C from Rust](advanced/ffi-c-from-rust.md)
114 | - [FFI Rust from C](advanced/ffi-rust-from-c.md)
115 | - [FFI Rust from Python](advanced/ffi-rust-from-python.md)
116 |
117 | # Further Learning
118 |
119 | ----
120 |
121 | - [Masterclasses](further-learning/rust-based-computer-science.md)
122 | - [Rust Based Computer Science](further-learning/rust-based-computer-science.md)
123 | - [Deep Dive into Strings in Rust](further-learning/deep-dive-into-string-in-rust.md)
124 | - [Building Microservices in Rust](further-learning/building-microservices-in-rust.md)
125 | - [Systems Programming in Rust](further-learning/systems-programming-in-rust.md)
126 | - [Projects](further-learning/cli-project.md)
127 | - [CLI Project](further-learning/cli-project.md)
128 | - [API Project](further-learning/api-project.md)
129 | - [Microservices Project](further-learning/mircoservices-project.md)
130 |
--------------------------------------------------------------------------------
/src/advanced/async-await-traits.md:
--------------------------------------------------------------------------------
1 | # async/.await
2 |
3 |
4 |
5 |
6 |
7 | #### Additional Resources
8 | - Starter guide to writing async Rust
9 | - Crust of Rust: async/await
10 |
11 | ## Exercises
12 |
13 | #### Awaiting
14 |
15 | ```rust,editable,compile_fail
16 | // When executing the below code nothing is printed to console. Can you guess what is missing?
17 |
18 | #[tokio::main]
19 | async fn main() {
20 | my_function();
21 | }
22 |
23 | async fn my_function() {
24 | println!("My first asynchronous function in rust!");
25 | }
26 | ```
27 |
28 |
29 | Solution
30 |
31 | ```rust
32 | #[tokio::main]
33 | async fn main() {
34 | my_function().await;
35 | }
36 |
37 | async fn my_function() {
38 | println!("My first asynchronous function in rust!");
39 | }
40 | ```
41 |
42 |
43 | #### Creating executor
44 |
45 | ```rust,editable,compile_fail
46 | // Fix the code to make it compile. You may only add code, not remove it.
47 |
48 | use std::time::Duration;
49 | use tokio::time::sleep;
50 |
51 | struct Employee {
52 | id: u32,
53 | name: String,
54 | salary: f32,
55 | }
56 |
57 | impl Employee {
58 | fn new(id: u32, name: &str, salary: f32) -> Self {
59 | Self {
60 | id,
61 | name: name.to_string(),
62 | salary,
63 | }
64 | }
65 | }
66 |
67 | fn main() {
68 | let (id1, id2) = (2, 3);
69 | let emp1 = read_details_from_db(id1).await.unwrap();
70 | let emp2 = read_details_from_db(id2).await.unwrap();
71 | if emp1.salary > emp2.salary {
72 | println!(
73 | "{} earns ${} more than {}",
74 | emp1.name,
75 | emp1.salary - emp2.salary,
76 | emp2.name
77 | );
78 | } else if emp2.salary > emp1.salary {
79 | println!(
80 | "{} earns ${} more than {}",
81 | emp2.name,
82 | emp2.salary - emp1.salary,
83 | emp1.name
84 | );
85 | } else {
86 | println!("Both {} and {} earn same amount", emp1.name, emp2.name);
87 | }
88 | }
89 |
90 | async fn read_details_from_db(id: u32) -> Result {
91 | // dummy read from database
92 | sleep(Duration::from_millis(1000)).await;
93 | let database = [
94 | Employee::new(1, "Alice", 98000.0),
95 | Employee::new(2, "Bob", 95000.0),
96 | Employee::new(3, "Cindy", 95000.0),
97 | ];
98 | for emp in database {
99 | if id == emp.id {
100 | return Ok(emp);
101 | }
102 | }
103 | Err("Employee record not present".into())
104 | }
105 | ```
106 |
107 |
108 | Solution
109 |
110 | ```rust
111 | use std::time::Duration;
112 | use tokio::time::sleep;
113 |
114 | struct Employee {
115 | id: u32,
116 | name: String,
117 | salary: f32,
118 | }
119 |
120 | impl Employee {
121 | fn new(id: u32, name: &str, salary: f32) -> Self {
122 | Self {
123 | id,
124 | name: name.to_string(),
125 | salary,
126 | }
127 | }
128 | }
129 |
130 | #[tokio::main]
131 | async fn main() {
132 | let (id1, id2) = (2, 3);
133 | let emp1 = read_details_from_db(id1).await.unwrap();
134 | let emp2 = read_details_from_db(id2).await.unwrap();
135 | if emp1.salary > emp2.salary {
136 | println!(
137 | "{} earns ${} more than {}",
138 | emp1.name,
139 | emp1.salary - emp2.salary,
140 | emp2.name
141 | );
142 | } else if emp2.salary > emp1.salary {
143 | println!(
144 | "{} earns ${} more than {}",
145 | emp2.name,
146 | emp2.salary - emp1.salary,
147 | emp1.name
148 | );
149 | } else {
150 | println!("Both {} and {} earn same amount", emp1.name, emp2.name);
151 | }
152 | }
153 |
154 | async fn read_details_from_db(id: u32) -> Result {
155 | // dummy read from database
156 | sleep(Duration::from_millis(1000)).await;
157 | let database = [
158 | Employee::new(1, "Alice", 98000.0),
159 | Employee::new(2, "Bob", 95000.0),
160 | Employee::new(3, "Cindy", 95000.0),
161 | ];
162 | for emp in database {
163 | if id == emp.id {
164 | return Ok(emp);
165 | }
166 | }
167 | Err("Employee record not present".into())
168 | }
169 | ```
170 |
171 |
--------------------------------------------------------------------------------
/src/advanced/attribute-like.md:
--------------------------------------------------------------------------------
1 | # Attribute Like
2 |
3 |
4 |
5 |
6 |
7 | ## Exercises
8 |
9 | (No exercises yet. Feel free to contribute here!)
10 |
--------------------------------------------------------------------------------
/src/advanced/calling-unsafe-functions.md:
--------------------------------------------------------------------------------
1 | # Calling Unsafe Functions
2 |
3 |
4 |
5 |
6 |
7 | ## Exercises
8 |
9 | #### Unsafe functions
10 |
11 | ```rust,editable,compile_fail
12 | // Fix the code to make it compile. You can only add and not remove anything from the code.
13 |
14 | fn increment(a: *mut i32) {
15 | *a += 1;
16 | }
17 |
18 | fn get_val(a: *const i32) -> i32 {
19 | *a
20 | }
21 |
22 | fn main() {
23 | let mut x = 0;
24 | let ptr1 = &mut x as *mut i32;
25 | unsafe {
26 | increment(ptr1);
27 | increment(ptr1);
28 | increment(ptr1);
29 | assert_eq!(get_val(ptr1), 3);
30 | }
31 | }
32 | ```
33 |
34 |
35 | Solution
36 |
37 | ```rust
38 | unsafe fn increment(a: *mut i32) {
39 | *a += 1;
40 | }
41 |
42 | unsafe fn get_val(a: *const i32) -> i32 {
43 | *a
44 | }
45 |
46 | fn main() {
47 | let mut x = 0;
48 | let ptr1 = &mut x as *mut i32;
49 | unsafe {
50 | increment(ptr1);
51 | increment(ptr1);
52 | increment(ptr1);
53 | assert_eq!(get_val(ptr1), 3);
54 | }
55 | }
56 | ```
57 |
58 |
59 | #### Unsafe methods
60 |
61 | ```rust,editable,compile_fail
62 | // Something is missing from the method signatures. Complete them wherever required.
63 |
64 | use std::ops::{Add, Mul, Sub};
65 |
66 | struct VarManipulator(*mut T)
67 | where
68 | T: Copy + Add