From the course: Rust Essential Training

Unlock the full course today

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

Challenge: Sum boxes

Challenge: Sum boxes - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Challenge: Sum boxes

- [Narrator] It's time for yet another challenge. This time to practice writing functions using generic types, boxes and the dereference operator. Your goal is to write a function that adds together two numbers stored within boxes. Your function should be named, sum_boxes. It should accept two input arguments. Which are both boxes containing the same generic data type, T. Which will be some type of integer or float. And your sum_boxes function should add together the numeric values contained within those two input boxes. And then return a new box containing the resulting sum. You can see two examples of how this function will be called by looking at the test code provided in the exercise files. Which initializes several boxes containing numbers. Passes them to the sum_boxes function. And then checks the results to make sure they're as expected. Even though adding two numbers together is a simple task, the requirement to…

Contents