Hi everyone,
I am new to Rust and looking to see how I can implement an algorithm in the Rust way.
The context is set in a school setting, where the system is keeping track of the student's score.
There are four subjects that a student can take.
enum Subject {
English, Math, Science, Geography
}
And each student will have the score stored together.
struct EnglishScore { score: i32 }
struct MathScore { score: i32 }
struct ScienceScore { score: i32 }
struct GeographyScore { score: i32 }
struct StudentSubjectScore {
english: EnglishScore,
math: MathScore,
science: ScienceScore,
geography: GeographyScore
}
And each of the language score struct
have a trait called ToSubject
that you can get the subject's enum.
trait ToSubject { fn get_subject() -> Subject; }
I want to be able to come out with a struct that is as follows that rank the subject from first to fourth.
struct StudentRankedSubject {
first: Subject,
second: Subject,
third: Subject,
fourth: Subject
}
Me having come from a OOP, Python and Ruby background.
I was thinking of implementing it as a Vec<i32>
of all the scores, sort them and retrieve it from a generated HashMap
.
But I realized I need to work through a number of Optional
and leading to a situation where there could be None
but not supposed to.
Just shouting out to see if anyone have a better solution out there.
Thanks in advanced!
JS