Skip to content

Commit

Permalink
Ignore a non-compiling test listing and add code to fix a test listing
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed May 15, 2019
1 parent d4d22f4 commit 29fe982
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/ch15-05-interior-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ implement a mock object to do just that, but the borrow checker won’t allow it

<span class="filename">Filename: src/lib.rs</span>

```rust,does_not_compile
```rust,ignore,does_not_compile
#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -275,6 +275,41 @@ shows what that looks like:
<span class="filename">Filename: src/lib.rs</span>

```rust
# pub trait Messenger {
# fn send(&self, msg: &str);
# }
#
# pub struct LimitTracker<'a, T: Messenger> {
# messenger: &'a T,
# value: usize,
# max: usize,
# }
#
# impl<'a, T> LimitTracker<'a, T>
# where T: Messenger {
# pub fn new(messenger: &T, max: usize) -> LimitTracker<T> {
# LimitTracker {
# messenger,
# value: 0,
# max,
# }
# }
#
# pub fn set_value(&mut self, value: usize) {
# self.value = value;
#
# let percentage_of_max = self.value as f64 / self.max as f64;
#
# if percentage_of_max >= 1.0 {
# self.messenger.send("Error: You are over your quota!");
# } else if percentage_of_max >= 0.9 {
# self.messenger.send("Urgent warning: You've used up over 90% of your quota!");
# } else if percentage_of_max >= 0.75 {
# self.messenger.send("Warning: You've used up over 75% of your quota!");
# }
# }
# }
#
#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -306,6 +341,7 @@ mod tests {
assert_eq!(mock_messenger.sent_messages.borrow().len(), 1);
}
}
# fn main() {}
```

<span class="caption">Listing 15-22: Using `RefCell<T>` to mutate an inner
Expand Down

0 comments on commit 29fe982

Please sign in to comment.