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 readpricesfilename: &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 az letter, followed by any number of such letters or space
characters
a semicolon ;
a price in cents any integer
c or cents.
Each of these can be separated by an arbitrary number of spaces. That includes 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 and 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
;filetxt
; sweet
ice cream; cents
; savory
sandwich;c
hot dog ; c
;filetxt
;icecream;cents
ice cream; cents
; lines below are invalid
goldfish; c
sandwich; c cents
;filetxt
cat ; cats are not snacks
chips ; c
;meow.txt this is a valid file
here kittykitty; c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
