Skip to content

Commit

Permalink
Use modmod exercises instead of absolute numbering and exercise path …
Browse files Browse the repository at this point in the history
…in exercise descripions
  • Loading branch information
hdoordt committed Aug 24, 2023
1 parent c9e97f4 commit b560372
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ Instructions on cloning the repository can be found here: <https://docs.github.c
Now that you've got the code on your machine, navigate to it using your favorite terminal and run:

```
cd exercises/0-intro
cd #[modmod:exercise_dir]
cargo run
```

This command may take a while to run the first time, as Cargo will first fetch the crate index from the registry.
It will compile and run the `intro` package, which you can find in `exercises/0-intro`.
It will compile and run the `intro` package, which you can find in `#[modmod:exercise_dir]`.
If everything goes well, you should see some output:

```
Compiling intro v0.1.0 (/home/henkdieter/tg/edu/101-rs/exercises/0-intro)
Compiling intro v0.1.0 ([REDACTED]/#[modmod:exercise_dir])
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
Running `target/debug/intro`
🦀 Hello, world! 🦀
You've successfully compiled and run your first Rust project!
```
If Rust-Analyzer is set up correctly, you can also click the '▶️ Run'-button that is shown in `exercises/0-intro/src/main.rs`.
If Rust-Analyzer is set up correctly, you can also click the '▶️ Run'-button that is shown in `#[modmod:exercise_dir]/src/main.rs`.
With CodeLLDB installed correctly, you can also start a debug session by clicking 'Debug', right next to the '▶️ Run'-button.
Play a little with setting breakpoints by clicking on a line number, making a red circle appear and stepping over/into/out of functions using the controls.
You can view variable values by hovering over them while execution is paused, or by expanding the 'Local' view under 'Variables' in the left panel during a debug session.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `excercises/A/6-error-handling/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `excercises/A/4-error-propagating/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Follow the instructions in the comments of `excercises/A/5-slices/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!
Don't take too much time on the extra assignment, instead come back later once
you've done the rest of the excercises.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `excercises/A/7-boxed-data/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ In this exercise, you will create a Rust crate that adheres to the guidelines th

*This exercise should be done in groups of 2 people*

### B.2.A Setting up ⭐
# #[modmod:exercise_ref].A Setting up ⭐
Create a new project using `cargo new --name quizzer`. Make sure it acts as both a binary and a library. That means there will be both a `src/lib.rs` and a `src/bin/quizzer/main.rs` file in your crate, where `quizzer` is the name of the binary:

```bash
Expand Down Expand Up @@ -43,7 +43,7 @@ serde_json = "1.0.87"

For `clap` and `serde`, the non-standard `derive` feature of each these crates is enabled. For `clap`, it allows us to derive the `Parser` trait, which greatly simplifies creating a CLI. The `derive` feaure from `serde` allows us to derive the `Serialize` and `Deserialize` traits on any struct we wish to serialize or deserialize using `serde` and its backends, in our case `serde_json`.

### B.2.B Quizzer ⭐⭐⭐
# #[modmod:exercise_ref].B Quizzer ⭐⭐⭐
This exercise is about both design and finding information. You'll have to figure out a model to represent your quiz questions, as well as a means to store them into a JSON file, and load them yourself. Also, you will have to find out how to parse the program arguments.

We will use the project we just set up to write a quiz game creator and player. You may add other dependencies as needed. It has the following functional requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The BSN is a number that adheres to some rules.
In this exercise, we will create a Rust type that guarantees that it represents a valid BSN.


### B.4.A Newtype ⭐⭐
# #[modmod:exercise_ref].A Newtype ⭐⭐
In this part we will implement the BSN number validation, as well as a fallible constructor.

A BSN is valid if and only if it matches the following criteria:
Expand All @@ -27,7 +27,7 @@ To try just the `test_validation` test case, run:
cargo test -- test_validation
```

### B.4.B Visitor with Serde ⭐⭐⭐
# #[modmod:exercise_ref].B Visitor with Serde ⭐⭐⭐
Next up is implementing the `serde::Serialize` and `serde::Deserialize` traits, to support serialization and deserialization of `Bsn`s.
In this case, simply deriving those traits won't suffice, as we want to represent the `BSN` as a string after serialization.
We also want to deserialize strings directly into `Bsn`s, while still upholding the guarantee that an instantiated `Bsn` represents a valid BSN.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Channels are a very useful way to communicate between threads and `async` tasks. They allow for decoupling your application into many tasks. You'll see how that can come in nicely in exercise E.2. In this exercise, you'll implement two variants: a oneshot channel and a multi-producer-single-consumer (MPSC) channel. If you're up for a challenge, you can write a broadcast channel as well.

### C.4.A MPSC channel ⭐⭐
# #[modmod:exercise_ref].A MPSC channel ⭐⭐
A multi-producer-single-consumer (MPSC) channel is a channel that allows for multiple `Sender`s to send many messages to a single `Receiver`.

Open `exercises/C/4-async-channels` in your editor. You'll find the scaffolding code there. For part A, you'll work in `src/mpsc.rs`. Fix the `todo!`s in that file in order to make the test pass. To test, run:
Open `#[modmod:exercise_dir]` in your editor. You'll find the scaffolding code there. For part A, you'll work in `src/mpsc.rs`. Fix the `todo!`s in that file in order to make the test pass. To test, run:

```bash
cargo test -- mpsc
```

If your tests are stuck, probably either your implementation does not use the `Waker` correctly, or it returns `Poll::Pending` where it shouldn't.

### C.4.B Oneshot channel ⭐⭐⭐
# #[modmod:exercise_ref].B Oneshot channel ⭐⭐⭐
A oneshot is a channel that allows for one `Sender` to send exactly one message to a single `Receiver`.

For part B, you'll work in `src/broadcast.rs`. This time, you'll have to do more yourself. Intended behavior:
Expand All @@ -29,7 +29,7 @@ To test, run:
cargo test -- broadcast
```

### C.4.B Broadcast channel (bonus) ⭐⭐⭐⭐
# #[modmod:exercise_ref].C Broadcast channel (bonus) ⭐⭐⭐⭐
A Broadcast channel is a channel that supports multiple senders and receivers. Each message that is sent by any of the senders, is received by every receiver. Therefore, the implemenentation has to hold on to messages until they have been sent to every receiver that has not yet been dropped. This furthermore implies that the message shoud be cloned upon broadcasting.

For this bonus exercise, we provide no scaffolding. Take your inspiration from the `mpsc` and `oneshot` modules, and implement a `broadcast` module yourself.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
In this exercise, you'll write a simple chat server and client based on [Tokio](https://lib.rs/crates/tokio). Open `exercises/C/5-async-chat` in your editor. The project contains a `lib.rs` file, in which a type `Message` resides. This `Message` defines the data the chat server and clients use to communicate.
In this exercise, you'll write a simple chat server and client based on [Tokio](https://lib.rs/crates/tokio). Open `#[modmod:exercise_dir]` in your editor. The project contains a `lib.rs` file, in which a type `Message` resides. This `Message` defines the data the chat server and clients use to communicate.

### C.5.A Server ⭐⭐⭐
# #[modmod:exercise_ref].A Server ⭐⭐⭐
The chat server, which resides in `src/bin/server.rs` listens for incoming TCP connections on port 8000, and spawns two tasks (futures):

- `handle_incoming`: reads lines coming in from the TCP connection. It reads the username the client provides, and broadcasts incoming `Messages`, possibly after some modification.
Expand All @@ -14,7 +14,7 @@ To start the server, run
cargo run --bin server
```

### C.5.B Client ⭐⭐
# #[modmod:exercise_ref].B Client ⭐⭐
The chat client, residing in `src/bin/client.rs` contains some todo's as well. Fix them to allow for registration and sending `Message`s to the server.

To start the client, run
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `exercises/C/1-tf-idf/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Follow the instructions in the comments of `exercises/C/2-mutex/src/main.rs`!

## C.3 Advanced Mutex (bonus) ⭐⭐⭐⭐

The basic mutex performs a spin-loop while waiting to take the lock. That is terribly inefficient. Luckily, your operating system is able to wait until the lock becomes available, and will just put the thread to sleep in the meantime.

This functionality is exposed in the [atomic_wait crate](https://docs.rs/atomic-wait/latest/atomic_wait/index.html). The [section on implementing a mutex](https://marabos.nl/atomics/building-locks.html#mutex) from "Rust Atomics and Locks" explains how to use it.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `exercises/F/1-linked-list/src/bin/unsafe.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/bin/unsafe.rs`!
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Follow the instructions in the comments of `exercises/F/3-tagged-union/src/main.rs`!
Follow the instructions in the comments of `#[modmod:exercise_dir]/src/main.rs`!

0 comments on commit b560372

Please sign in to comment.