-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add basic rust guide #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
GuillaumeDecMeetsMore
merged 8 commits into
master
from
guillaume/feat/add-basic-rust-guide
Aug 18, 2025
+159
−24
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4562a8
feat: add basic rust guide
GuillaumeDecMeetsMore b391158
Merge branch 'master' into guillaume/feat/add-basic-rust-guide
GuillaumeDecMeetsMore c438fbe
Merge branch 'master' into guillaume/feat/add-basic-rust-guide
GuillaumeDecMeetsMore 89fe2f3
Merge branch 'master' into guillaume/feat/add-basic-rust-guide
GuillaumeDecMeetsMore adf3a02
Merge branch 'master' into guillaume/feat/add-basic-rust-guide
GuillaumeDecMeetsMore f6c7bab
Update docs/rust.md
GuillaumeDecMeetsMore ce6e62f
Merge branch 'master' into guillaume/feat/add-basic-rust-guide
GuillaumeDecMeetsMore 2ea9ff0
chore: rework a little the small rust guide
GuillaumeDecMeetsMore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # New to Rust | ||
|
|
||
| As Rust is a relatively new language compared to older languages such as C, Java, and even Javascript, it can be useful to have a rough overview of what makes Rust interesting, and how it differs from these languages (with a heavy focus on Typescript for us). | ||
|
|
||
| First, what is Rust ? | ||
|
|
||
| Rust is a modern systems programming language focused on **performance**, **safety**, and **concurrency**, without needing a garbage collector. It's often compared to C++, as it's wehre its advantages can shine the best (safety without sacrificing performance). | ||
GuillaumeDecMeetsMore marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| While its main domain is systems programming, it's also a very good language for writing backends. Of course, for most backends/APIs, having awesome performance isn't a hard requirement, and is often considered overkill compared to the complexity that is required to achieve it. But, one of the big advantages of Rust compared to other languages (C++, C, ...) is that it allows to achieve it while providing a lot of safety mechanisms. This includes the borrow checker, but it also includes the explicit handling of `undefined` values (via Option<>) and of errors (via Result<>). | ||
mm-derek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For backends, it's mainly compared to Golang, as both are performant compiled languages that can be used for backends. Both have their advantages and disadvantages, but we could argue that Rust is more oriented towards safety, at the cost of increased complexity, while Golang is more oriented towards simplicity, which makes it easy to learn, use, and understand. | ||
mm-derek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Comparisons with Typescript | ||
mm-derek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### 🦀 Variables are immutable by default | ||
|
|
||
| ```ts | ||
| // Typescript | ||
mm-derek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let x = 5; | ||
| x = 6; | ||
| ``` | ||
|
|
||
| ```rust | ||
| let x = 5; | ||
| // x = 6; // ❌ Error: x is immutable | ||
| let mut x = 5; | ||
| x = 6; // ✅ Use `mut` to make variables mutable | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🧱 Strong, static typing (but with great inference) | ||
|
|
||
| ```ts | ||
| let name: string = "Alice"; | ||
| ``` | ||
|
|
||
| ```rust | ||
| let name: &str = "Alice"; // or just `let name = "Alice";` — Rust infers types | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🚫 No `null` or `undefined` — use `Option` | ||
|
|
||
| ```ts | ||
| function getUser(): User | null {} | ||
| ``` | ||
|
|
||
| ```rust | ||
| fn get_user() -> Option<User> { | ||
| // Some(user) or None | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🎯 Pattern matching with `match` | ||
|
|
||
| ```ts | ||
| const role = "admin"; | ||
| switch (role) { | ||
| case "admin": | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| ```rust | ||
| match role.as_str() { | ||
| "admin" => { /* ... */ } | ||
| _ => { /* ... */ } | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🎒 Ownership and borrowing (the big Rust idea) | ||
|
|
||
| Rust tracks memory **at compile time** — no GC. | ||
|
|
||
| ```ts | ||
| function takeName(name: string) {} | ||
| const myName = "Bob"; | ||
| takeName(myName); // OK, string is copied | ||
| ``` | ||
|
|
||
| ```rust | ||
| fn take_name(name: String) {} | ||
| let my_name = String::from("Bob"); | ||
| take_name(my_name); // OK, but ownership moved | ||
| // my_name is no longer valid here | ||
| ``` | ||
|
|
||
| Use references to **borrow** data instead of moving it: | ||
|
|
||
| ```rust | ||
| fn print_name(name: &String) {} | ||
| print_name(&my_name); // ✅ Borrowing, no move | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 🧵 Async is explicit | ||
|
|
||
| Rust doesn't have a built-in runtime like Node — you pick one (like `tokio` or `async-std`). | ||
|
|
||
| ```ts | ||
| async function fetchData() {} | ||
| ``` | ||
|
|
||
| ```rust | ||
| async fn fetch_data() {} | ||
| ``` | ||
|
|
||
| To run async functions, use `.await` inside an async runtime. | ||
|
|
||
| --- | ||
|
|
||
| ### 🛠 Enums with data | ||
|
|
||
| Rust enums are more powerful than TS unions. | ||
|
|
||
| ```ts | ||
| type Result<T> = { ok: true; value: T } | { ok: false; error: string }; | ||
| ``` | ||
|
|
||
| ```rust | ||
| enum Result<T, E> { | ||
| Ok(T), | ||
| Err(E), | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 📦 Dependencies use `Cargo.toml` | ||
|
|
||
| Like `package.json`, but for Rust. | ||
|
|
||
| ```toml | ||
| [dependencies] | ||
| serde = "1.0" | ||
| tokio = { version = "1.0", features = ["full"] } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 📚 Tooling is great | ||
|
|
||
| - `cargo build` — compile | ||
| - `cargo run` — run the app | ||
| - `cargo test` — run tests | ||
| - `cargo fmt` — format code | ||
| - `cargo clippy` — linter | ||
|
|
||
| --- | ||
|
|
||
| ### ✅ When in doubt, check the compiler | ||
|
|
||
| Rust’s compiler is very strict — but its error messages are famously helpful. Trust it! | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.