Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program is just so I can really understand the beginning part of the minigrep
- project in the Rust book. I know it doesn't really look much like this but I am
- trying to write my own version, so I really learn these concepts. I have many errors in
- this program and a few I have never encountered before.
- The program is supposed to take two strings from the Config struct and print them out.
- I don't really understand the whole impl thing yet. I might have made things too
- complicated with the extra function just for printing out but I'm going for learning
- how impl works.
- */
- fn main() {
- let file = String::from("noodle.txt");
- let search_string = String::from("Apple");
- let config = Config::new(file, search_string);
- config.print_inputs()
- }
- struct Config {
- search_string: String, //What does it mean about specifying a lifetime?
- file_to_search: String,
- }
- impl Config { //Is this implemented correctly?
- fn new(file: String, string: String) -> Config { //Self as a perameter or I get error:
- Config { file_to_search: file, search_string: string }
- }
- fn print_inputs(&self) {
- println!("Search for {} in {}.", self.search_string, self.file_to_search);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement