rustlings/exercises
Robert Schäfer 1832aba31e docs: less ambiguity in quiz3
Motivation
----------
I'm currently doing the rustlings course. I was pretty lost at quiz3 because I did not understand the problem.

With this change I would have understood that it should be possible to use both `f32` or `&str` for the grade.

I also googled quiz3 and found that other people got confused and used enums: https://www.reddit.com/r/learnrust/comments/wccx7s/rustlings_blocked_on_quiz3/

<details>
  <summary>My solution, hopefully I got it now</summary>

```
// quiz3.rs
//
// This quiz tests:
// - Generics
// - Traits
//
// An imaginary magical school has a new report card generation system written
// in Rust! Currently the system only supports creating report cards where the
// student's grade is represented numerically (e.g. 1.0 -> 5.5). However, the
// school also issues alphabetical grades (A+ -> F-) and needs to be able to
// print both types of report card!
//
// Make the necessary code changes in the struct ReportCard and the impl block
// to support alphabetical report cards. Change the Grade in the second test to
// "A+" to show that your changes allow alphabetical grades.
//
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

use std::fmt::Display;

pub struct ReportCard<T: Display> {
    pub grade: T,
    pub student_name: String,
    pub student_age: u8,
}

impl <T: Display> ReportCard<T> {
    pub fn print(&self) -> String {
        format!("{} ({}) - achieved a grade of {}",
            &self.student_name, &self.student_age, &self.grade)
    }
}

mod tests {
    use super::*;

    #[test]
    fn generate_numeric_report_card() {
        let report_card = ReportCard {
            grade: 2.1,
            student_name: "Tom Wriggle".to_string(),
            student_age: 12,
        };
        assert_eq!(
            report_card.print(),
            "Tom Wriggle (12) - achieved a grade of 2.1"
        );
    }

    #[test]
    fn generate_alphabetic_report_card() {
        // TODO: Make sure to change the grade here after you finish the exercise.
        let report_card = ReportCard {
            grade: "A+",
            student_name: "Gary Plotter".to_string(),
            student_age: 11,
        };
        assert_eq!(
            report_card.print(),
            "Gary Plotter (11) - achieved a grade of A+"
        );
    }
}
 ```

</details>
2023-11-06 15:15:59 +05:30
..
clippy remove hint comments when no hint exists 2023-09-15 22:29:55 +02:00
conversions fix: test name typo 2023-09-14 17:10:06 +02:00
enums Fixed formatting with rust-analyzer 2023-09-13 20:26:47 +02:00
error_handling fix(errors1): change Result to Option in exersise description 2023-08-25 21:49:22 +02:00
functions docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
generics docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
hashmaps Merge branch 'main' into comment_cleanup 2023-06-12 12:39:02 +02:00
if Merge pull request #1599 from szabgab/if1-test-case 2023-09-04 13:55:10 +02:00
intro docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
iterators Convert other exercises that have assertions to test mode 2023-08-27 01:06:01 +02:00
lifetimes docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
macros docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
modules docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
move_semantics Merge pull request #1641 from mo8it/move-semantics5-test 2023-09-06 09:31:46 +02:00
options docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
primitive_types remove hint comments when no hint exists 2023-09-15 22:29:55 +02:00
smart_pointers Fix compiler error and clarify instructions 2023-09-08 09:49:11 -07:00
strings docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
structs Use u32 instead of i32 2023-08-29 00:52:11 +02:00
tests docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
threads Merge pull request #1641 from mo8it/move-semantics5-test 2023-09-06 09:31:46 +02:00
traits docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
variables docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
vecs docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
quiz1.rs docs: dedup repeated sentence 2023-07-21 14:42:19 +02:00
quiz2.rs docs: cleanup the explanation paragraphs at the start of each exercise. 2023-05-29 18:41:51 +01:00
quiz3.rs docs: less ambiguity in quiz3 2023-11-06 15:15:59 +05:30
README.md added existing chapter for clippy to mapping 2023-01-01 02:34:58 +01:00

Exercise to Book Chapter mapping

Exercise Book Chapter
variables §3.1
functions §3.3
if §3.5
primitive_types §3.2, §4.3
vecs §8.1
move_semantics §4.1-2
structs §5.1, §5.3
enums §6, §18.3
strings §8.2
modules §7
hashmaps §8.3
options §10.1
error_handling §9
generics §10
traits §10.2
tests §11.1
lifetimes §10.3
iterators §13.2-4
threads §16.1-3
smart_pointers §15, §16.3
macros §19.6
clippy §21.4
conversions n/a