Challenge
Now it's time for you to take your first steps with Rust! Here's a challenge to get you started:
-
Initialize a Rust application in a brand new directory
- If you have cloned the GitHub repository there is a folder called
scratchwhich containsdevcontainers.jsonfile. You can use this to launch a devcontainer for Rust development, as well as working through all the examples and challenges.
- If you have cloned the GitHub repository there is a folder called
-
Open the
src/main.rsfile in your editor and modify the "Hello, world!" message to include your name. -
Run the application to see your changes
-
Try adding a second line to the program that prints the current date and time.
Hint: You'll need to add the
chronocrate to your dependencies, and the documentation should help you find the functions you need. -
Run the application again to see both lines printed.
Congratulations! You've written, modified, and run your first Rust program, and you've learned how to add and use external dependencies. In the next module, we'll dive deeper into Rust's memory safety features and how they compare to .NET.
Remember: the Rust compiler is your friend. If you get error messages, read them carefully - they often tell you exactly what's wrong and how to fix it!
If you're struggling, you can find a solution on GitHub. Try it on your own first, if you're finding it difficult that's good. It means you're learning.