Polymorphism
As Rust is pretty low level for a high level language, it pays to understand how polymorphism works under the hood. This is what this chapter is for.
Each type that implements a trait also implements a table with pointers to each implemented function from that trait, in a defined order.
This is called a virtual table and normally transparent to the programmer, but you could use this knowledge to implement polymorphism manually, if you wish so. Programmers of C-style languages may know the virtual
keyword, this is where its name comes from.
Now, a reference to a trait object actually includes two pointers: One to the object data and one to the virtual table of the object type. To call a method on a trait object, the program will take the offset of a trait function, calculated by the compiler from the defined order, and apply it on the virtual table pointer, yielding a pointer (directed at the virtual table) to a pointer of the trait function implementation of that type. It then jumps there and executes the function. As said, this is completely transparent to the programmer, but this is how polymorphism works under the hood.