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] [workspace]
members = [ "example/*", "exercise/*" ] members = [ "example/*", "exercise/*" ]
resolver = "2"

View File

@@ -1,6 +1,6 @@
# Ultimate Rust 2: Intermediate Concepts # 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! 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. - Open up the `src/main.rs` file.
- Follow the numbered exercise instructions in the code comments. - 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. 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 [exercises]: https://github.com/CleanCut/ultimate_rust2#exercises
[`example/`]: https://github.com/CleanCut/ultimate_rust2/blob/main/example [`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 [Ultimate Rust Crash Course]: https://agileperception.com/ultimate_rust_crash_course
[Rust in 3 Weeks]: https://agileperception.com [Rust in 3 Weeks]: https://agileperception.com
[Ultimate Rust 2: Intermediate Concepts]: https://github.com/CleanCut/ultimate_rust2 [Ultimate Rust 2: Intermediate Concepts]: https://github.com/CleanCut/ultimate_rust2

View File

@@ -1,6 +1,8 @@
// START IN lib.rs! // START IN lib.rs!
use aquarium::Dolphin; 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?) // (You already did #1 in lib.rs, right?)
// //

View File

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

View File

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

View File

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

View File

@@ -46,7 +46,7 @@ fn main() {
// println!("The default Party is\n{:#?}", Party::default()); // 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. // 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 // Hint: The trick to struct update syntax is specifying the value(s) you want to customize