Rust Quote Generator
Create a Rust program that generates random inspirational quotes. This is a fun and practical exercise for learning Rust's data structures, random number generation, and basic program flow. A quote generator can be a starting point for many applications, from personal productivity tools to website content.
Problem Description
Your task is to build a command-line application in Rust that, when executed, prints a random inspirational quote. The program should have a predefined collection of quotes and authors, and each time it runs, it should select one quote at random and display it.
Key Requirements:
- Quote Storage: Store a collection of quotes, each associated with its author.
- Random Selection: Implement logic to randomly select one quote from the collection.
- Output Format: Display the selected quote and its author in a clear, readable format.
- No External Dependencies (initially): For this challenge, aim to use Rust's standard library for random number generation.
Expected Behavior:
Upon running the executable, the program should output something like:
"The only way to do great work is to love what you do." - Steve Jobs
or
"Believe you can and you're halfway there." - Theodore Roosevelt
Each execution should potentially yield a different quote.
Edge Cases:
- Empty Quote List: While not strictly required for this initial challenge, consider how your program might handle a scenario where the quote list is empty (though you will be providing a populated list).
Examples
Example 1:
Input: (No explicit input required from the user at runtime)
Output:
"The future belongs to those who believe in the beauty of their dreams." - Eleanor Roosevelt
Explanation: The program randomly selected this quote and its author from its internal collection and printed it to the console.
Example 2:
Input: (No explicit input required from the user at runtime)
Output:
"Strive not to be a success, but rather to be of value." - Albert Einstein
Explanation: A different quote was randomly selected and displayed.
Example 3:
Input: (No explicit input required from the user at runtime)
Output:
"It always seems impossible until it's done." - Nelson Mandela
Explanation: Another random quote selection.
Constraints
- The collection of quotes should contain at least 10 distinct quotes with their authors.
- The program must be written entirely in Rust, using the standard library.
- The program should not require any user input at runtime.
- Performance is not a critical constraint for this challenge, but the generation should be near-instantaneous.
Notes
- Consider using a
structto represent a quote and its author, or perhaps aVecof tuples or&strpairs. - Rust's
randcrate is a popular choice for random number generation, but for this challenge, you can start with thestd::time::SystemTimefor a basic seed or explore other standard library options if available for simpler PRNGs. (For a more robust solution, you'd typically use therandcrate, but let's stick tostdfor now). - Think about how to iterate through your collection and pick a random index.