From 29fe982990e43b9367be0ff47abc82fb2123fd03 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 15 May 2019 17:48:40 -0400 Subject: [PATCH] Ignore a non-compiling test listing and add code to fix a test listing --- src/ch15-05-interior-mutability.md | 38 +++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index c730d02bf3..f43d549244 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -195,7 +195,7 @@ implement a mock object to do just that, but the borrow checker won’t allow it Filename: src/lib.rs -```rust,does_not_compile +```rust,ignore,does_not_compile #[cfg(test)] mod tests { use super::*; @@ -275,6 +275,41 @@ shows what that looks like: Filename: src/lib.rs ```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 { +# 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::*; @@ -306,6 +341,7 @@ mod tests { assert_eq!(mock_messenger.sent_messages.borrow().len(), 1); } } +# fn main() {} ``` Listing 15-22: Using `RefCell` to mutate an inner