I am creating an object of tesla
, that comes from the struct of Car
.
The way each car gets energy to work is different, in the case of a Tesla, we plug in a cable and pass electricity, in the case of a Honda, we insert oil into a tank. I want my car struct to have a property of get_energy
with a Fn
datatype, so that when I create a new car I can pass in a function that will be called when I call tesla.get_energy()
... the creation of tesla would ideally be something like let tesla = Car(get_energy: || => {grab_cable(), insert_cable(), pass_electricty()})
which would look different from the creation of a Honda. Can I somehow do that?