Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Exercise: method and traits: change output" #2548

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/methods-and-traits/exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ method. Code which might log its progress can then take an `&impl Logger`. In
testing, this might put messages in the test logfile, while in a production
build it would send messages to a log server.

However, the `StdoutLogger` given below logs all messages, regardless of
However, the `StderrLogger` given below logs all messages, regardless of
verbosity. Your task is to write a `VerbosityFilter` type that will ignore
messages above a maximum verbosity.

Expand Down
10 changes: 5 additions & 5 deletions src/methods-and-traits/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ pub trait Logger {
fn log(&self, verbosity: u8, message: &str);
}

struct StdoutLogger;
struct StderrLogger;

impl Logger for StdoutLogger {
impl Logger for StderrLogger {
fn log(&self, verbosity: u8, message: &str) {
println!("verbosity={verbosity}: {message}");
eprintln!("verbosity={verbosity}: {message}");
}
}
// ANCHOR_END: setup

/// Only log messages up to the given verbosity level.
struct VerbosityFilter {
max_verbosity: u8,
inner: StdoutLogger,
inner: StderrLogger,
}

impl Logger for VerbosityFilter {
Expand All @@ -44,7 +44,7 @@ impl Logger for VerbosityFilter {

// ANCHOR: main
fn main() {
let logger = VerbosityFilter { max_verbosity: 3, inner: StdoutLogger };
let logger = VerbosityFilter { max_verbosity: 3, inner: StderrLogger };
logger.log(5, "FYI");
logger.log(2, "Uhoh");
}
Expand Down
Loading