Exercise 07-11
authorGreg Burri <greg.burri@gmail.com>
Sat, 26 Oct 2024 10:36:45 +0000 (12:36 +0200)
committerGreg Burri <greg.burri@gmail.com>
Sat, 26 Oct 2024 10:36:45 +0000 (12:36 +0200)
exercises/07_threads/11_locks/src/lib.rs
exercises/07_threads/11_locks/src/store.rs

index b5e6c0d..7a7db1a 100644 (file)
@@ -60,7 +60,7 @@ enum Command {
     },
 }
 
-pub fn server(receiver: Receiver<Command>) {
+fn server(receiver: Receiver<Command>) {
     let mut store = TicketStore::new();
     loop {
         match receiver.recv() {
index 9387499..306e662 100644 (file)
@@ -28,13 +28,13 @@ impl TicketStore {
             description: ticket.description,
             status: Status::ToDo,
         };
-        todo!();
+        self.tickets.insert(id, Arc::new(Mutex::new(ticket)));
         id
     }
 
     // The `get` method should return a handle to the ticket
     // which allows the caller to either read or modify the ticket.
-    pub fn get(&self, id: TicketId) -> Option<todo!()> {
-        todo!()
+    pub fn get(&self, id: TicketId) -> Option<Arc<Mutex<Ticket>>> {
+        self.tickets.get(&id).cloned()
     }
 }