#Please explain me this concept.
31 messages · Page 1 of 1 (latest)
what kind of programming experience do you have?
right, so javascript for example
when you use e.g. console.log you don't actually care what the type is, you just want to print it, right?
Yap
this is an example of being to use different types interchangeably
the only thing we really care about is that the object can be printed
so its basically more type safe?
It allows you to "mimic" inheritance
and your Box<dyn Animal> is one way to do that. it's one way to return an object, but we don't actually care what type it is, just that it implements the Animal trait
^
eh, i don't think this would be the right way to phrase it. I guess you could say it's a way to do patterns that you might reach for inheritance for in other languages
Yeah it's not precise
You essentially give your structs a common denominator, by implementing a common trait for them
really interesting
but, i think the basic question is "why is polymorphism useful and why would i want to use it"
and traits are a way to abstract over some property and use types interchangeably
really cool. ive been doing a gui for my company for a while now and im pretty limited with my rust knowledge. i was able to make it functional. hehe thanks for help.
right, so you might have some kind of Component, Input etc traits
what does the *self do
*self is like the pointer stuff in c++ and other languages?
uh &x is a pointer heh
dereferencing?