From dad4fd7e6684ffa911c1298e374a56d63a56710e Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 23 Aug 2021 14:07:13 +0200 Subject: [PATCH] File reading with standard fs API --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() { -- 2.39.2