Returning abstract types

Remember when we used Box to create trait objects in order to hide the exact implementation returned, and instead only give guarantees about implemented traits? That required us to accept some overhead, as a Box allocates its resources on the heap; however, on the current nightly, things are different. You can use the impl trait syntax introduced in this recipe to return objects as their trait directly on the stack, all without boxes. At the moment, this only works for returned types, but the syntax is planned to be extended to most places where you could write a concrete type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.203