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 - Rust Tutorial
From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
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
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to modules1m 5s
-
(Locked)
Demo: Using Cargo for dependencies5m 25s
-
(Locked)
Demo: Extending with modules4m 52s
-
(Locked)
Demo: Verify code with doctest5m
-
(Locked)
Demo: Defining public and private modules6m 12s
-
(Locked)
Demo: Private and public fields in structs10m 26s
-
(Locked)
Summary of modules1m 5s
-
(Locked)
-
-