Challenge: Learning the Rust Environment
Test your understanding of the basics of Rust by creating documentation for a given piece of code.
We'll cover the following
Challenge
In this challenge, we'll explore the capabilities of Cargo. We'll leverage Cargo to perform tasks similar to those covered in this section. Emphasizing the importance of code documentation, our goal is to implement a straightforward Rust function. This function takes two integers as inputs and returns their sum. To enhance understanding for anyone reviewing the code, we’ll also provide comprehensive documentation for this function.
Task
You have been provided with a main.rs
file in the widget below, containing only a main()
function. Your task is to augment the file by adding both code and documentation as follows:
Task 1
Your primary objective is to develop a function named add_nums()
with the following specifications:
Accepts two arguments, both of type
i32
Returns a value of type
i32
Task 2
Additionally, you are required to craft comprehensive documentation for the add_nums()
function. This documentation should cover the following aspects:
Purpose of the function: Clearly articulate the intended purpose and functionality of the
add_nums()
function.Input parameters and types: Document the input parameters, providing a brief description of each and specifying their data types.
Return value and type: Define the output of the function, including the type of the returned value.
Special considerations or constraints: If applicable, highlight any unique considerations or constraints associated with using this function.
Try it yourself
Code the function implementation and its documentation in the widget below. Press the "Run” button below to excute the cargo doc
command.
Get hands-on with 1400+ tech skills courses.