Skip to content

Commit 039e032

Browse files
Desktop application Course (#12)
* overview * course modules * remove sqlite and diesel * reorder * added: lessons 01,02,03,04, and exercises tab for the rust chapter * ownership * added: new exercise, lessons 07,08,09,10,11,12 * added: on data, lesson 01, 02, on networking 01, 02, 05 * added project ideas --------- Co-authored-by: robertDinca2003 <robert20031114@gmail.com>
1 parent 547e188 commit 039e032

25 files changed

+10959
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
Welcome to **Desktop Applications with Rust & Slint**!
4+
This week, you will learn to create **desktop applications**, using **Rust** for the business logic and **Slint** for the graphical interface.
5+
6+
The course is structured to gradually take you from the fundamentals of Rust, to UI integration, and finally to completing a full project that you will present at the end of the camp.
7+
8+
---
9+
10+
## Course Tutors
11+
- **Precup Cristiana**
12+
- **Robert Dincă**
13+
14+
---
15+
16+
## Course Structure
17+
18+
1. **Rust for Desktop Apps** – Learn Rust fundamentals, data modeling, and local data storage
19+
2. **Building UIs with Slint** – Create interactive desktop interfaces and handle user events
20+
3. **Networking & APIs** – Fetch and display external data in your applications
21+
4. **Final Project** – Build and present a complete desktop application
22+
23+
---
24+
25+
## What is this course about?
26+
27+
This course is about **building real desktop applications** from start to finish.
28+
29+
You will take an idea, turn it into a working app with an interface, and by the end, you’ll have a **complete desktop application** you can run and showcase.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Installing and configuring
3+
---
4+
5+
### Setting Up the Rust Development Environment
6+
7+
Alright, let's get your computer ready to write some Rust code\! The easiest and official way to install Rust is using `rustup`.
8+
9+
1. **Open Your Terminal/Command Prompt:**
10+
11+
- **Linux/macOS:** Open your regular terminal application.
12+
- **Windows:** Open PowerShell or Command Prompt. (If you're using VS Code, its integrated terminal works great\!)
13+
14+
2. **Install `rustup`:**
15+
16+
- **Linux/macOS:** Copy and paste this command into your terminal and press Enter. Follow the on-screen prompts (usually just pressing Enter for default options).
17+
```bash
18+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
19+
```
20+
- **Windows:**
21+
- Go to the official `rustup` download page: [https://rustup.rs/](https://rustup.rs/)
22+
- Download the appropriate installer for your system (e.g., `rustup-init.exe` for 64-bit Windows).
23+
- Run the installer and follow the instructions. Choose the default installation options.
24+
25+
3. **Configure Your Shell (Important for Linux/macOS):**
26+
27+
- After `rustup` finishes on Linux/macOS, it will often tell you to run a command to add Rust to your system's `PATH`. This is usually:
28+
```bash
29+
source "$HOME/.cargo/env"
30+
```
31+
- Run this command in your _current_ terminal session. To make it permanent, you might need to add it to your shell's configuration file (like `.bashrc`, `.zshrc`, or `.profile`).
32+
33+
4. **Verify Installation:**
34+
35+
- Close and reopen your terminal/command prompt (or run the `source` command).
36+
- Type these commands to check if Rust and Cargo (Rust's build tool, which comes with `rustup`) are installed correctly:
37+
```bash
38+
rustc --version
39+
cargo --version
40+
```
41+
- You should see version numbers printed for both `rustc` (the Rust compiler) and `cargo`. If you do, congratulations, Rust is installed\!
42+
43+
5. **Install VS Code (Recommended IDE):**
44+
- If you don't have it already, download and install Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/)
45+
6. **Install the `Rust Analyzer` Extension:** This is crucial for a great Rust development experience in VS Code (code completion, error checking, formatting, etc.). Open VS Code, go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X), search for "Rust Analyzer", and install it.
46+
47+
7. **Install the `Slint` Extension:** This is recommanded for a better development experience, featuring auto-complition, go-to definition, refactoring, syntax coloration, and a live preview and editing of Slint GUIs.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Project Structure
3+
---
4+
5+
**What is Cargo?**
6+
7+
Cargo is Rust's **build system and package manager** which streamlines almost every aspect of your Rust workflow:
8+
9+
- **Project Creation:** `cargo new` quickly sets up a new Rust project with the correct structure.
10+
- **Building:** `cargo build` compiles your code into an executable program.
11+
- **Running:** `cargo run` builds and then executes your program.
12+
- **Testing:** `cargo test` runs your project's tests.
13+
14+
Let's create our classic "Hello, world\!" program using Cargo.
15+
16+
1. **Create a New Project:**
17+
- In your terminal, navigate to a directory where you want to create your project (e.g., your Desktop or a `dev` folder).
18+
- Run this command:
19+
```bash
20+
cargo new hello_rust_app
21+
```
22+
- Cargo will create a new folder named `hello_rust_app` with a basic project structure inside.
23+
2. **Explore the Project Structure:**
24+
- Navigate into the new folder: `cd hello_rust_app`
25+
- Look at the contents:
26+
- `Cargo.toml`: This is the manifest file for your project. It contains metadata about your project (name, version) and lists its dependencies.
27+
- `src/main.rs`: This is where your main Rust code lives.
28+
- `target/`: (Created after you build) This is where compiled executable files go.
29+
3. **Examine `src/main.rs`:**
30+
- Open `src/main.rs` in your VS Code. You'll see:
31+
```rust
32+
fn main() {
33+
println!("Hello, world!");
34+
}
35+
```
36+
- `fn main()`: This is the main function, the entry point of every Rust executable program.
37+
- `println!`: This is a **macro** (indicated by the `!`). It prints text to the console.
38+
4. **Run Your Application:**
39+
- In your terminal (make sure you're inside the `hello_rust_app` folder), run:
40+
```bash
41+
cargo run
42+
```
43+
- **What happens?**
44+
- Cargo first **compiles** your code (you'll see messages like "Compiling hello_rust_app v0.1.0...").
45+
- Then, it **executes** the compiled program.
46+
- You should see: `Hello, world!` printed in your terminal.
47+
48+
Congratulations\! You've just created and run your very first Rust application.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Variables and data types
3+
---
4+
5+
Now let's dive into how Rust handles variables and data. This is where you'll see some key differences from languages like JavaScript or Python.
6+
7+
#### **Immutability by Default:**
8+
This is one of Rust's core principles. By default, variables in Rust are **immutable**, meaning once you give them a value, you cannot change that value. This helps prevent unexpected bugs.
9+
10+
* **Declaring an Immutable Variable:**
11+
```rust
12+
fn main() {
13+
let x = 5; // 'x' is immutable. Its value is 5, and it cannot be changed.
14+
println!("The value of x is: {}", x);
15+
// x = 6; // This would cause a compile-time error! Try uncommenting it.
16+
// println!("The value of x is: {}", x);
17+
}
18+
```
19+
20+
* **Making a Variable Mutable:**
21+
If you *do* want to change a variable's value, you must explicitly mark it as `mut` (short for mutable).
22+
```rust
23+
fn main() {
24+
let mut y = 10; // 'y' is mutable. We can change its value.
25+
println!("The initial value of y is: {}", y);
26+
y = 15; // This is allowed because 'y' is mutable.
27+
println!("The new value of y is: {}", y);
28+
}
29+
```
30+
#### **Type Inference vs. Explicit Types:**
31+
Rust is a **statically typed** language, meaning it knows the type of every variable at compile time. However, it's also very smart and can often **infer** the type based on the value you assign. You don't always *have* to write the type.
32+
* **Type Inference (Common):**
33+
```rust
34+
fn main() {
35+
let age = 30; // Rust infers 'age' is an integer (i32 by default)
36+
let pi = 3.14; // Rust infers 'pi' is a floating-point number (f64 by default)
37+
let is_active = true; // Rust infers 'is_active' is a boolean
38+
let initial = 'A'; // Rust infers 'initial' is a character (single quotes)
39+
let greeting = "Hello"; // Rust infers 'greeting' is a string slice (&str)
40+
println!("Age: {}, Pi: {}, Active: {}, Initial: {}, Greeting: {}", age, pi, is_active, initial, greeting);
41+
}
42+
```
43+
* **Explicit Type Annotation (When needed or for clarity):**
44+
You can explicitly tell Rust the type of a variable. This is useful when inference is ambiguous or for better readability.
45+
```rust
46+
fn main() {
47+
let count: i64 = 100_000_000_000; // Explicitly a 64-bit integer
48+
let temperature: f32 = 25.5; // Explicitly a 32-bit float
49+
let message: &str = "Welcome!"; // Explicitly a string slice
50+
println!("Count: {}, Temp: {}, Message: {}", count, temperature, message);
51+
}
52+
```
53+
#### **Common Primitive Data Types:**
54+
Rust has several built-in primitive types:
55+
* **Integers:** `i8`, `i16`, `i32` (default), `i64`, `i128` (signed integers) and `u8`, `u16`, `u32`, `u64`, `u128` (unsigned integers). The number indicates the bits they use. `isize` and `usize` depend on the architecture (e.g., 32-bit or 64-bit).
56+
* **Floating-Point Numbers:** `f32` (single-precision), `f64` (double-precision, default).
57+
* **Booleans:** `bool` (`true` or `false`).
58+
* **Characters:** `char` (single Unicode scalar value, uses single quotes, e.g., `'A'`, `'😊'`).
59+
* **Strings:** We'll learn more about strings later, but for now, know that `&str` (string slice, immutable reference to text) and `String` (growable, owned string) are the main types.
60+
61+
#### **Constants:**
62+
63+
Constants are always immutable and must have their type explicitly annotated. They can be declared in any scope, including global.
64+
65+
```rust
66+
const MAX_POINTS: u32 = 100_000; // Constants are typically named in SCREAMING_SNAKE_CASE
67+
const APP_VERSION: &str = "1.0.0";
68+
fn main() {
69+
println!("Max points: {}", MAX_POINTS);
70+
println!("App version: {}", APP_VERSION);
71+
}
72+
```
73+
74+
#### **Shadowing:**
75+
76+
Rust allows you to declare a *new* variable with the same name as a previous variable. This "shadows" the previous variable, meaning the new variable takes precedence. This is different from `mut`, as you're creating a new variable, not changing an existing one.
77+
```rust
78+
fn main() {
79+
let spaces = " "; // First 'spaces' variable (string slice)
80+
println!("Spaces (initial): '{}'", spaces);
81+
let spaces = spaces.len(); // 'spaces' is now a new variable, holding the length (an integer)
82+
println!("Spaces (length): {}", spaces); // The old 'spaces' is no longer accessible
83+
}
84+
```
85+
Shadowing is useful when you want to transform a variable's value but keep the same name, without needing to make the original variable mutable.

0 commit comments

Comments
 (0)