I have a struct like this:
struct TeddyBear {
mood: Option<Box<dyn Mood>>,
}
"Mood" is a trait
. Now there are two possible moods: "Happy" and "Sleepy", struct
s that implement the trait
. I've drafted a playground example here.
I'm trying to learn the best way to get the current mood of the teddy-bear at different times in the program.
What I did was to return string values particular to each mood, but it feels somewhat hackish. An enum
of values would likely work too, but I would have to remember to add to it each time a new Mood is added. I would like to know if there's a way to use "Happy" or "Sleepy" directly.
Thank you!