From 28a1bb94ada020477c559be6352c2cc256f6cb58 Mon Sep 17 00:00:00 2001 From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 14 May 2024 14:56:22 +0200 Subject: [PATCH] Use &str rather than &String --- book/src/05_ticket_v2/04_if_let.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/src/05_ticket_v2/04_if_let.md b/book/src/05_ticket_v2/04_if_let.md index 562f800..1b567c3 100644 --- a/book/src/05_ticket_v2/04_if_let.md +++ b/book/src/05_ticket_v2/04_if_let.md @@ -4,7 +4,7 @@ Your solution to the previous exercise probably looks like this: ```rust impl Ticket { - pub fn assigned_to(&self) -> &String { + pub fn assigned_to(&self) -> &str { match &self.status { Status::InProgress { assigned_to } => assigned_to, Status::Done | Status::ToDo => { @@ -29,7 +29,7 @@ Here's how you can use `if let` to simplify the `assigned_to` method: ```rust impl Ticket { - pub fn assigned_to(&self) -> &String { + pub fn assigned_to(&self) -> &str { if let Status::InProgress { assigned_to } = &self.status { assigned_to } else { @@ -46,7 +46,7 @@ you can use the `let/else` construct: ```rust impl Ticket { - pub fn assigned_to(&self) -> &String { + pub fn assigned_to(&self) -> &str { let Status::InProgress { assigned_to } = &self.status else { panic!("Only `In-Progress` tickets can be assigned to someone"); }; -- 2.45.2