Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. This program is just so I can really understand the beginning part of the minigrep
  3. project in the Rust book. I know it doesn't really look much like this but I am
  4. trying to write my own version, so I really learn these concepts. I have many errors in
  5. this program and a few I have never encountered before.
  6.  
  7. The program is supposed to take two strings from the Config struct and print them out.
  8. I don't really understand the whole impl thing yet. I might have made things too
  9. complicated with the extra function just for printing out but I'm going for learning
  10. how impl works.
  11. */
  12.  
  13. fn main() {
  14. let file = String::from("noodle.txt");
  15. let search_string = String::from("Apple");
  16.  
  17. let config = Config::new(file, search_string);
  18. config.print_inputs()
  19. }
  20.  
  21. struct Config {
  22. search_string: String, //What does it mean about specifying a lifetime?
  23. file_to_search: String,
  24. }
  25.  
  26. impl Config { //Is this implemented correctly?
  27. fn new(file: String, string: String) -> Config { //Self as a perameter or I get error:
  28. Config { file_to_search: file, search_string: string }
  29. }
  30.  
  31. fn print_inputs(&self) {
  32. println!("Search for {} in {}.", self.search_string, self.file_to_search);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement