mirror of
https://github.com/rust-lang/book.git
synced 2026-12-04 11:14:57 -06:00
Ignore a non-compiling test listing and add code to fix a test listing
This commit is contained in:
@@ -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::*;
|
||||
@@ -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::*;
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user