From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Sum boxes

Solution: Sum boxes - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Solution: Sum boxes

(upbeat music) - [Instructor] The my solution to the sum boxes challenge, I started by building a function definition based on the requirements of the challenge. Those requirements said that the function should be named sum boxes, that it would be using a single generic type T, so I'll need to define that after the function name in ankle brackets. And then that the function should accept two input parameters. I'll simply name the first parameter A, and it will be the type box T. And the second parameter will be named B. And it's also a box T. Finally, the return value from this function should also be a box T. Now, I don't want to add the two input boxes themselves together, I want to add the values stored within those boxes. To access those values, I'll need to use the dereference operator on A and B to follow both box pointers to the values they're storing underneath. This expression will add those two stored…

Contents