From: Martin Pitt Date: Mon, 23 Aug 2021 12:07:13 +0000 (+0200) Subject: File reading with standard fs API X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=commitdiff_plain;h=dad4fd7e6684ffa911c1298e374a56d63a56710e File reading with standard fs API --- diff --git a/src/main.rs b/src/main.rs index 441cc79..c07c405 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() {