mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-11 20:13:30 +02:00
feat: quiz3 done of traits and generics
This commit is contained in:
@@ -12,18 +12,18 @@
|
|||||||
// block to support alphabetical report cards in addition to numerical ones.
|
// block to support alphabetical report cards in addition to numerical ones.
|
||||||
|
|
||||||
// TODO: Adjust the struct as described above.
|
// TODO: Adjust the struct as described above.
|
||||||
struct ReportCard {
|
struct ReportCard<T> {
|
||||||
grade: f32,
|
grade: T,
|
||||||
student_name: String,
|
student_name: String,
|
||||||
student_age: u8,
|
student_age: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Adjust the impl block as described above.
|
// TODO: Adjust the impl block as described above.
|
||||||
impl ReportCard {
|
impl<T: std::fmt::Display> ReportCard<T> {
|
||||||
fn print(&self) -> String {
|
fn print(&self) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{} ({}) - achieved a grade of {}",
|
"{} ({}) - achieved a grade of {}",
|
||||||
&self.student_name, &self.student_age, &self.grade,
|
self.student_name, self.student_age, self.grade,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user