Skip to content

Commit

Permalink
Revert "Exercise: method and traits: change output (#2383)"
Browse files Browse the repository at this point in the history
This reverts commit 29dcb0c.
  • Loading branch information
Alx-Lai authored Jan 14, 2025
1 parent 0c91136 commit 0551b66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 0551b66

Please sign in to comment.