November 2017
Intermediate to advanced
264 pages
5h 45m
English
Our function sqroot from the previous section is generic and works for any Float type. The compiler creates a different executable sqroot method for any type it is supposed to work with, in this case the f32 and f64 type. Rust applies this mechanism when a function call is polymorphic, that is when a function can accept arguments of different type. This is called static dispatch (also called compile-time polymorphism) and there is no runtime overhead involved. This is in contrast to how Java interfaces work, where the dispatching is done dynamically in runtime by the JVM. However Rust also has a form of dynamic dispatch (also called runtime polymorphism), using so called trait objects.
For an example of static ...
Read now
Unlock full access