Exercise 07-06
authorGreg Burri <greg.burri@gmail.com>
Thu, 24 Oct 2024 14:16:18 +0000 (16:16 +0200)
committerGreg Burri <greg.burri@gmail.com>
Thu, 24 Oct 2024 14:16:18 +0000 (16:16 +0200)
exercises/07_threads/06_interior_mutability/src/lib.rs

index 37d4d4f..311279b 100644 (file)
@@ -6,18 +6,18 @@ use std::rc::Rc;
 
 pub struct DropTracker<T> {
     value: T,
-    counter: todo!(),
+    counter: Rc<RefCell<i32>>,
 }
 
 impl<T> DropTracker<T> {
-    pub fn new(value: T, counter: todo!()) -> Self {
+    pub fn new(value: T, counter: Rc<RefCell<i32>>) -> Self {
         Self { value, counter }
     }
 }
 
 impl<T> Drop for DropTracker<T> {
     fn drop(&mut self) {
-        todo!()
+        *self.counter.borrow_mut() += 1;
     }
 }