Skip to content

Instantly share code, notes, and snippets.

@kriogenia
Created May 16, 2022 18:00
Show Gist options
  • Save kriogenia/bad8304308f9f65db799db01bcd70a98 to your computer and use it in GitHub Desktop.
Save kriogenia/bad8304308f9f65db799db01bcd70a98 to your computer and use it in GitHub Desktop.
Generics on Rust - StudentRecord Generic No-Extra
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