mc lang project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lib.rs 920B

123456789101112131415161718192021222324252627282930313233343536
  1. use std::io;
  2. use std::io::Read;
  3. use std::fs::File;
  4. pub fn read_file(filename: &str) -> Result<String, std::io::Error> {
  5. // get the first filename
  6. let mut en_us_lang_file = String::new();
  7. let mut en_us_lang = String::new();
  8. println!("Please specify the location of the {} file:", &filename);
  9. match io::stdin().read_line(&mut en_us_lang_file) {
  10. Ok(_) => (),
  11. Err(e) => return Err(e),
  12. };
  13. let en_us_lang_file = en_us_lang_file.trim();
  14. let f = File::open(&en_us_lang_file);
  15. let mut f = match f {
  16. Ok(file) => file,
  17. Err(e) => {
  18. println!("There was an error opening the file.");
  19. return Err(e);
  20. },
  21. };
  22. match f.read_to_string(&mut en_us_lang) {
  23. Ok(_) => (),
  24. Err(e) => {
  25. println!("There was an error reading the file.");
  26. return Err(e);
  27. },
  28. };
  29. Ok(en_us_lang)
  30. }