Question: PROGRAM IN RUST Your program will print a Rust Vector that you create by continually pushing tokens onto it. This assignment is intended to give

PROGRAM IN RUST

PROGRAM IN RUST Your program will print a Rust Vector that youcreate by continually pushing tokens onto it. This assignment is intended togive you practice with the following concepts: enums Vectors pattern matching andmatch expressions For this program, you will: Create an enum called Quantitywith the following variants: o One (doesn't store any data) O ACouple

Your program will print a Rust Vector that you create by continually pushing tokens onto it. This assignment is intended to give you practice with the following concepts: enums Vectors pattern matching and match expressions For this program, you will: Create an enum called Quantity with the following variants: o One (doesn't store any data) O ACouple (doesn't store any data) AFew (doesn't store any data) o Several (doesn't store any data) Amount (stores a u32) Create an enum called Token with the following variants: o Amount (stores a Quantity, the previous enum that you create) Character (stores a char) o Whitespace (doesn't store any data) Write a program function that does the following: o Accepts one program argument that is the name of a file Reads the contents of the given file into a string Creates a Vec called tokens . Loops through the string character by character o Creates a Token object each iterations based on the current character o Pushes the Token onto tokens o Prints tokens 4 Writing Your Program You will want to put #[derive (Debug)] above your two enums (Quantity and Token). If you want to use the ? operator in your main function, then you will need to: use the appropriate library (use std::error:: Error;) write the appropriate function signature for main (fn main() -> Result> {}) return Ok(()) at the end of main You will want to iterate through the contents of the file using a string iterator (call chars() on the String). You will want to match on the current character. See the documentation for pattern syntax. If you run into any problems, please ask for help on Slack. ts print_tokens. rs test1.txt UTCDTLV Muu 1 cu > rustc print_tokens.rs > /print_tokens test.txt [Character('H'), Character('e'), Character('l'), Character('l'), Character('o'), Whitespace, Amount (One), Character(','), Whitespace, Amount (Acouple), Character (','), Whitespace, Amount (AFew), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Se veral), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Other(8)), Character(','), Whitespace, Amount(Other(9)), Character(','), Whitespace, Character('a'), Character('n'), Character('d'), Whitespace, Character('t'), Character('e'), Character('n'), Character('.'), Whitespace] Your program will print a Rust Vector that you create by continually pushing tokens onto it. This assignment is intended to give you practice with the following concepts: enums Vectors pattern matching and match expressions For this program, you will: Create an enum called Quantity with the following variants: o One (doesn't store any data) O ACouple (doesn't store any data) AFew (doesn't store any data) o Several (doesn't store any data) Amount (stores a u32) Create an enum called Token with the following variants: o Amount (stores a Quantity, the previous enum that you create) Character (stores a char) o Whitespace (doesn't store any data) Write a program function that does the following: o Accepts one program argument that is the name of a file Reads the contents of the given file into a string Creates a Vec called tokens . Loops through the string character by character o Creates a Token object each iterations based on the current character o Pushes the Token onto tokens o Prints tokens 4 Writing Your Program You will want to put #[derive (Debug)] above your two enums (Quantity and Token). If you want to use the ? operator in your main function, then you will need to: use the appropriate library (use std::error:: Error;) write the appropriate function signature for main (fn main() -> Result> {}) return Ok(()) at the end of main You will want to iterate through the contents of the file using a string iterator (call chars() on the String). You will want to match on the current character. See the documentation for pattern syntax. If you run into any problems, please ask for help on Slack. ts print_tokens. rs test1.txt UTCDTLV Muu 1 cu > rustc print_tokens.rs > /print_tokens test.txt [Character('H'), Character('e'), Character('l'), Character('l'), Character('o'), Whitespace, Amount (One), Character(','), Whitespace, Amount (Acouple), Character (','), Whitespace, Amount (AFew), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Se veral), Character(','), Whitespace, Amount (Several), Character(','), Whitespace, Amount (Other(8)), Character(','), Whitespace, Amount(Other(9)), Character(','), Whitespace, Character('a'), Character('n'), Character('d'), Whitespace, Character('t'), Character('e'), Character('n'), Character('.'), Whitespace]

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 Databases Questions!