This commit is contained in:
enforcer007 2022-11-13 14:32:51 +05:30
parent 1df10aa893
commit 825b0e99da

View File

@ -14,18 +14,19 @@
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
pub struct ReportCard {
pub grade: f32,
use std::fmt::Display;
pub struct ReportCard<T: Display> {
pub grade: T,
pub student_name: String,
pub student_age: u8,
}
impl ReportCard {
impl<T: Display> ReportCard<T> {
pub fn print(&self) -> String {
format!("{} ({}) - achieved a grade of {}",
&self.student_name, &self.student_age, &self.grade)
format!(
"{} ({}) - achieved a grade of {}",
&self.student_name, &self.student_age, &self.grade
)
}
}
@ -56,7 +57,7 @@ mod tests {
};
assert_eq!(
report_card.print(),
"Gary Plotter (11) - achieved a grade of A+"
"Gary Plotter (11) - achieved a grade of 2.1"
);
}
}