Question: Code is in Rust. Will be checked. Can only use regex crate and standard rust library. No unsafe. pub fn read _ prices ( filename:

Code is in Rust.
Will be checked. Can only use regex crate and standard rust library. No unsafe.
pub fn read_prices(filename: &str)-> Option>
Given a txt file, parse and return the items sold by a vending machine, along with their prices. Alternatively, return None if the file has an invalid
format.
Each line of the the file must either be a price listing or a comment.
Price listings consist of the following in the order shown:
an item name (starts with an uppercase ( A - Z ) or lowercase ( a-z ) letter, followed by any number of such letters or space
characters)
a semi-colon ;
a price in cents (any integer)
c or cents.
Each of these can be separated by an arbitrary number of spaces. That includes 0 spaces. These should not be included in your
hashmap. (You may assume no spaces at the very beginning of a line.)
Comment lines start with ; and can contain any characters after that. They should be ignored.
Validity:
An item's price must be between 1 and 50 cents (inclusive). An item must appear at most once in the file, duplicates are not allowed. If any of
these rules are violated, or if any line has an invalid format, you must return None .
You can use the regex crate to implement the rules above. Example Files
```
;file1.txt
; sweet
ice cream; 10 cents
; savory
sandwich;49c
hot dog ; 49 c
```
;file2.txt
;icecream;10cents
ice cream; 10 cents
; lines below are invalid
goldfish; 100c
sandwich; 49c cents
;file3.txt
cat ; cats are not snacks
chips ; 20c
;meow.txt (this is a valid file)
here kittykitty; 1c
Code is in Rust. Will be checked. Can only use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!