Use &str rather than &String

This commit is contained in:
LukeMathWalker 2024-05-14 14:56:22 +02:00
parent 3d534dd336
commit 28a1bb94ad

View file

@ -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");
};