Compare commits

...

10 Commits

Author SHA1 Message Date
7194a5d29e Complete exercise: idomatic 2026-05-17 22:45:35 +04:00
Nathan Stocks
5e852ca5d5 fix typo 2025-10-30 16:29:28 -06:00
Nathan Stocks
0b362a2a7b freshen up 2025-10-30 16:16:10 -06:00
Nathan Stocks
1b1ced37a4 just in case someone tries to use rusty_engine from within this repo 2023-02-10 20:24:11 -07:00
Magnus Markling
de71e01a95 even more 2022-09-19 14:11:25 -06:00
Magnus Markling
c100b83038 Remove more extra spaces 2022-09-19 14:11:25 -06:00
Magnus Markling
5c0dfcda33 Remove extra space from excercise 2022-09-19 14:11:25 -06:00
Jamil Lambert, PhD
ea93715738 Updated the comment to match the code
The code requires the student to create a Party not  a Dessert as originally stated in the comment
2022-09-14 10:31:47 -06:00
Korny666
036e7b7b50 // Silence some warnings so they don't distract from the exercise. clippy::vec_init_then_push is distracting here 2022-03-09 14:29:38 -07:00
Nathan Stocks
a47afbbb6e fix logic for logging step 5, output should now trigger two errors in a row 2022-02-20 14:20:49 -07:00
8 changed files with 36 additions and 19 deletions

View File

@@ -1,2 +1,3 @@
[workspace]
members = [ "example/*", "exercise/*" ]
resolver = "2"

View File

@@ -1,6 +1,6 @@
# Ultimate Rust 2: Intermediate Concepts
This is the companion repository for the `Ultimate Rust 2: Intermediate Concepts` (the followup to the popular [Ultimate Rust Crash Course]). _UR2IC_ will be published independently online in the second half of 2021 and is also presented live as part of some O'Reilly virtual events such as [Rust in 3 Weeks], or taught in-person for corporate training. You will get the most out of this training experience by doing the [exercises] in this repository and watching (or attending) the instructor-led training.
This is the companion repository for the `Ultimate Rust 2: Intermediate Concepts` (the followup to the popular [Ultimate Rust Crash Course]). You will get the most out of this training experience by doing the [exercises] in this repository and watching (or attending) the instructor-led training.
In other words, this repository is for you hands-on-learners!
@@ -22,7 +22,7 @@ The exercises are separate Rust projects inside the `exercises/` subdirectory.
- Open up the `src/main.rs` file.
- Follow the numbered exercise instructions in the code comments.
If you encounter any problems with the exercises, please feel free to use the online course communication tools to contact me, or [open an discussion]. Either way. 😄
If you encounter any problems with the exercises, please feel free to use the online course communication tools to contact me, or [open a discussion]. Either way. 😄
For your convenience, here is a list of all the exercises, with links to view the code on GitHub.
@@ -55,7 +55,7 @@ If you like the work I do, please consider sponsoring me [on GitHub] or [on Patr
[exercises]: https://github.com/CleanCut/ultimate_rust2#exercises
[`example/`]: https://github.com/CleanCut/ultimate_rust2/blob/main/example
[open an discussion]: https://github.com/CleanCut/ultimate_rust2/discussions/new
[open a discussion]: https://github.com/CleanCut/ultimate_rust2/discussions/new
[Ultimate Rust Crash Course]: https://agileperception.com/ultimate_rust_crash_course
[Rust in 3 Weeks]: https://agileperception.com
[Ultimate Rust 2: Intermediate Concepts]: https://github.com/CleanCut/ultimate_rust2

View File

@@ -1,6 +1,8 @@
// START IN lib.rs!
use aquarium::Dolphin;
// Silence some warnings so they don't distract from the exercise.
#[allow(clippy::vec_init_then_push)]
// (You already did #1 in lib.rs, right?)
//

View File

@@ -8,16 +8,28 @@
// Challenge: Clippy doesn't find *everything*. What else would you change to make this code better?
const pi:f32=3.14159265358979323846;
fn count_to_5()->i32{let mut foo =0;loop{if foo>pi as i32{if foo > 5{break;}}foo=foo+1;}return 5;}
fn main() {
println!("I can count to {}", count_to_5());
use std::f32::consts::PI;
fn count_to_5() -> i32 {
let mut count = 0;
loop {
if count > PI as i32 && count >= 5 {
break;
}
count += 1;
}
count
}
fn main() {
println!("I can count to {}", count_to_5());
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_counting() {
assert_eq!(count_to_5() == 5, true);
}
use super::*;
#[test]
fn test_counting() {
assert_eq!(count_to_5() == 5, true);
}
}

View File

@@ -26,8 +26,9 @@ impl Frog {
}
}
pub fn sleep(&mut self) {
if !self.sleeping {
if self.sleeping {
// 5. Use error!() to log a (non-fatal) error stating that the Frog is already asleep
} else {
self.sleeping = true;
}
}

View File

@@ -19,6 +19,7 @@ fn main() {
skippy.hop();
skippy.hop();
skippy.sleep();
skippy.sleep();
// Challenge: Go back to lib.rs and set the `target: ` argument for each logging call to be the
// path to the function. For example, `Frog::new`

View File

@@ -18,7 +18,7 @@ fn expensive_sum(v: Vec<i32>) -> i32 {
fn main() {
let my_vector = vec![2, 5, 1, 0, 4, 3];
// 1. Spawn a child thread and have it call `expensive_sum(my_vector)`. Store the returned
// 1. Spawn a child thread and have it call `expensive_sum(my_vector)`. Store the returned
// join handle in a variable called `handle`. Once you've done this you should be able to run
// the code and see the output from the child thread's expensive sum in the middle of the main
// thread's processing of letters.
@@ -79,8 +79,8 @@ fn main() {
});
// Using a Receiver channel as an iterator is a convenient way to get values until the channel
// gets closed. A Receiver channel is automatically closed once all Sender channels have been
// closed. Both our threads automatically close their Sender channels when they exit and the
// gets closed. A Receiver channel is automatically closed once all Sender channels have been
// closed. Both our threads automatically close their Sender channels when they exit and the
// destructors for the channels get automatically called.
for msg in rx {
println!("Main thread: Received {}", msg);
@@ -90,10 +90,10 @@ fn main() {
// - Use the thread handles to join both threads without getting any compiler warnings.
*/
// Challenge: Make two child threads and give them each a receiving end to a channel. From the
// Challenge: Make two child threads and give them each a receiving end to a channel. From the
// main thread loop through several values and print each out and then send it to the channel.
// On the child threads print out the values you receive. Close the sending side in the main
// thread by calling `drop(tx)` (assuming you named your sender channel variable `tx`). Join
// thread by calling `drop(tx)` (assuming you named your sender channel variable `tx`). Join
// the child threads.
println!("Main thread: Exiting.")
}

View File

@@ -46,7 +46,7 @@ fn main() {
// println!("The default Party is\n{:#?}", Party::default());
// 4. You prefer Maple Bacon cake. Use "struct update syntax" to create a Dessert with `cake`
// 4. You prefer Maple Bacon cake. Use "struct update syntax" to create a Party with `cake`
// set to `Cake::MapleBacon`, but the rest of the values are default.
//
// Hint: The trick to struct update syntax is specifying the value(s) you want to customize