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 25,600 courses taught by industry experts.

Demo: Private and public fields in structs

Demo: Private and public fields in structs

- [Instructor] We now know how to verify things with doctest. We also know how to control publicly versus private availability or scope. So let's actually go ahead and create a new module. It's going to be called config.rs, and we're going to say, "This module contains the configuration options for the application," and what we're going to do here is we're going to start creating a logging configuration. So we're going to say public enum LogLevel, how about LogLevel? And for LogLevel, we'll have Debug, Info, Warn, and Error. That looks correct to me. We'll start creating all of the configuration options that we want for this, and, now, we're going to say, how about LogOutput? And for LogOutput, we're going to have standard out, standard error, File(String), which is a string is going to say, if we want to configure a log output to go to a path or just to standard out or just to standard error, it will figure that out. Next, we're going to have a struct called logging, and we're going…

Contents