More Teachers
We'll cover the following...
I’m not happy with just talking about teachers. I want to know if the teacher is teaching math or art. Let’s rewrite our Job
type as:
Press + to interact
enum Job {ArtTeacher,MathTeacher,Scientist,}
This works, but I don’t like it that much. I’ll give you two reasons why; first, let’s say that I want to write a method is_teacher
. With the enum
above, I can write something like:
Press + to interact
impl Person {fn is_teacher(&self) -> bool {match self.job {Job::ArtTeacher => true,Job::MathTeacher => true,Job::Scientist => false,}}}
As I started adding physics, economics, and other teachers, this is just going to keep growing. I don’t like that. There’s nothing in the Job
enum telling me that there’s some ...