mirror of
https://github.com/mainmatter/100-exercises-to-learn-rust
synced 2024-12-26 21:58:49 +01:00
Use &str rather than &String
This commit is contained in:
parent
3d534dd336
commit
28a1bb94ad
1 changed files with 3 additions and 3 deletions
|
@ -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");
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue