mirror of
https://github.com/mainmatter/100-exercises-to-learn-rust
synced 2025-01-15 15:41:03 +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
|
```rust
|
||||||
impl Ticket {
|
impl Ticket {
|
||||||
pub fn assigned_to(&self) -> &String {
|
pub fn assigned_to(&self) -> &str {
|
||||||
match &self.status {
|
match &self.status {
|
||||||
Status::InProgress { assigned_to } => assigned_to,
|
Status::InProgress { assigned_to } => assigned_to,
|
||||||
Status::Done | Status::ToDo => {
|
Status::Done | Status::ToDo => {
|
||||||
|
@ -29,7 +29,7 @@ Here's how you can use `if let` to simplify the `assigned_to` method:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl Ticket {
|
impl Ticket {
|
||||||
pub fn assigned_to(&self) -> &String {
|
pub fn assigned_to(&self) -> &str {
|
||||||
if let Status::InProgress { assigned_to } = &self.status {
|
if let Status::InProgress { assigned_to } = &self.status {
|
||||||
assigned_to
|
assigned_to
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,7 @@ you can use the `let/else` construct:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
impl Ticket {
|
impl Ticket {
|
||||||
pub fn assigned_to(&self) -> &String {
|
pub fn assigned_to(&self) -> &str {
|
||||||
let Status::InProgress { assigned_to } = &self.status else {
|
let Status::InProgress { assigned_to } = &self.status else {
|
||||||
panic!("Only `In-Progress` tickets can be assigned to someone");
|
panic!("Only `In-Progress` tickets can be assigned to someone");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue