These tasks describe common idioms required for writing well-designed and idiomatic Rust code.
❗️Before completing this task you should complete all its sub-tasks.
After doing them you should be able to answer the following questions:
- Why should I care about types and expressing things in types? How do types help to increase guarantees of a program being correct?
- What is essential for writing well-designed and ergonomic APIs in Rust and why?
- Why
mem::replaceexists and what purpose does it solve? When and why is it really helpful? - How input type polymorphism is usually organized in Rust APIs? What cost does it have?
- Which ways and tools do exist for future-proofing source code in Rust?
Estimated time: 2 days
Design and implement a VendingMachine type, which behaves like a vending machine:
Productshould have a price and a name;VendingMachineshould have a limited capacity ofProducts;VendingMachineshould be able to give change;VendingMachineshould reject purchase if it cannot give change;Coinnominal values could only be1,2,5,10,20and50.
Make its usage API as convenient as you're capable to.