From 6a6d9c52e6e39ed5a8a1b132fb9fe41a5abff882 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 14 Mar 2017 22:10:01 +0000 Subject: [PATCH] Read file --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..fa5a1fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,14 @@ -fn main() { - println!("Hello, world!"); +use std::fs::File; +use std::io::Read; + +fn read_file(path : &str) -> String { + let mut data = File::open(path).unwrap(); + let mut buffer = String::new(); + data.read_to_string(&mut buffer); + return buffer; +} + +fn main() { + let data = read_file("test.yml"); + println!("{:?}", data); }