Compare commits
10 Commits
2129073c03
...
7194a5d29e
| Author | SHA1 | Date | |
|---|---|---|---|
|
7194a5d29e
|
|||
|
|
5e852ca5d5 | ||
|
|
0b362a2a7b | ||
|
|
1b1ced37a4 | ||
|
|
de71e01a95 | ||
|
|
c100b83038 | ||
|
|
5c0dfcda33 | ||
|
|
ea93715738 | ||
|
|
036e7b7b50 | ||
|
|
a47afbbb6e |
@@ -1,2 +1,3 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [ "example/*", "exercise/*" ]
|
members = [ "example/*", "exercise/*" ]
|
||||||
|
resolver = "2"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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?)
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -8,16 +8,28 @@
|
|||||||
|
|
||||||
// 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 main() {
|
fn count_to_5() -> i32 {
|
||||||
println!("I can count to {}", count_to_5());
|
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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
|
||||||
fn test_counting() {
|
#[test]
|
||||||
assert_eq!(count_to_5() == 5, true);
|
fn test_counting() {
|
||||||
}
|
assert_eq!(count_to_5() == 5, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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`
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user