Created
May 16, 2022 18:00
-
-
Save kriogenia/bad8304308f9f65db799db01bcd70a98 to your computer and use it in GitHub Desktop.
Generics on Rust - StudentRecord Generic No-Extra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
pub struct StudentRecord<T> { | |
student_id: u32, | |
marks: Vec<T>, | |
} | |
impl<T> StudentRecord<T> { | |
pub fn new(student_id: u32) -> Self { | |
Self { | |
student_id, | |
marks: Vec::new(), | |
} | |
} | |
pub fn add_mark(&mut self, mark: T) { | |
self.marks.push(mark); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment