100-exercises-to-learn-rust icon indicating copy to clipboard operation
100-exercises-to-learn-rust copied to clipboard

Prefer borrowing over ownership

Open dariocurr opened this issue 8 months ago • 0 comments

Hi, I am Dario from hiop.

First of all, thank you for this repo. This repo is gold for startups like us who want to build rust skills in our teams.

I was following the exercises you kindly provided and when I had to deal with 06x(15, 16), I proposed a different solution.

The part involved is the following:

  • https://github.com/mainmatter/100-exercises-to-learn-rust/blob/38dea384537077225888f3487be83501386cd851/exercises/06_ticket_management/15_hashmap/src/lib.rs#L59-L65

Following the principle of Preferring borrowing over ownership, the whole point is that the get and get_mut methods for TicketStore IMHO should take a reference as input, since the HashMap and BTreeMap ones don't require ownership

  • https://github.com/dariocurr/100-exercises-to-learn-rust/blob/f3ba66fe5b8ca873ba2e12b6e5b135f61c1c22f6/exercises/06_ticket_management/15_hashmap/src/lib.rs#L59-L65

What's your take on this?

Linked to #63

dariocurr avatar May 27 '24 11:05 dariocurr