]> piware.de Git - learn-rust.git/commitdiff
File reading with standard fs API
authorMartin Pitt <martin@piware.de>
Mon, 23 Aug 2021 12:07:13 +0000 (14:07 +0200)
committerMartin Pitt <martin@piware.de>
Mon, 23 Aug 2021 12:07:13 +0000 (14:07 +0200)
src/main.rs

index 441cc79a44db49e65227afdacfa575de42e96fb9..c07c4051165861365a2176a3c1edec6957d16903 100644 (file)
@@ -2,7 +2,7 @@ mod word_utils;
 
 use std::collections::HashMap;
 use std::io::{prelude::*, ErrorKind};
-use std::fs::File;
+use std::fs::{self, File};
 
 use word_utils::{first_word, second_word};
 
@@ -108,6 +108,12 @@ fn test_files() {
         Ok(s) => println!("Cargo.toml contents:\n{}\n-------------", s),
         Err(e) => println!("Could not open Cargo.toml: {:?}", e)
     }
+
+    // using std API
+    match fs::read_to_string("Cargo.toml") {
+        Ok(s) => println!("Cargo.toml contents:\n{}\n-------------", s),
+        Err(e) => println!("Could not open Cargo.toml: {:?}", e)
+    }
 }
 
 fn main() {