There's more...

You might have noticed that returning a Box<Iterator> or a Box<Error> comes at a small cost in terms of efficiency, as it requires moving an object onto the heap without it having any reason to go there. There are currently two ways around this.

For Box<Error>, you should instead create an own Error type, combining all the possible errors that can be returned from your function. This is detailed in Chapter 6, Handling Errors; Providing user-defined Error types.

For Box<Iterator>, you can analyze the compiler's output in order to find out the exact true type that you're returning. This works for small iterators, but any complex iterator will take a long time to crack. Because this situation is not really desirable, the Rust team has approved the introduction of abstract types, which will be introduced in Chapter 10, Using Experimental Nightly Features; Returning abstract types because it has not yet hit stable Rust.

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

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