From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development

Unlock this course with a free trial

Join today to access over 26,200 courses taught by industry experts.

Demo: Verify code with doctest

Demo: Verify code with doctest

- [Instructor] We've been adding functions and functionality to other files. We've been declaring them on lib.rs. We're saying pub mod colors and we've been making a lot of changes and we've been documented, so this is great, but how do we verify everything's working? We don't have a main function. This is not an executable, we have a lib.rs, how can we try to make sure that we're doing the right thing? Well, when we start documenting things like these with the triple, with the triple back slashes in this way, you are essentially creating documentation for your project. But this documentation is also executable. Do you see this use statement right there? That means that that's required to make this example work. And we have a thing that you may have noticed that is called run doctest. So what is that and how can we make use of that? Well, if I click on it, we will get output and I'm going to close file explorer here and we can say test result ok, so what is it actually testing? Well…

Contents