feat : Read File via File and BufReader.

This commit is contained in:
Usairim Isani 2020-07-30 15:59:08 +05:00
parent 38a615f407
commit ac20bf69dc
5 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,7 @@
### Stdio
Rust Supports STDIO i.e input from stdin and output to stdout and stderr
### Rust Book Section
[STDIO](https://doc.rust-lang.org/std/io/index.html)

View file

@ -0,0 +1,5 @@
orem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet enim eget ante efficitur elementum id consequat justo. Donec neque sapien, placerat ut dignissim iaculis, auctor feugiat augue. Cras mattis suscipit tristique. Quisque lacus tortor, bibendum at fringilla eget, pharetra non arcu. Curabitur ac risus quis quam congue dapibus quis eleifend sapien. Integer tempor semper molestie. Mauris pellentesque est non leo bibendum ultricies. Nulla convallis a dui quis vestibulum. Curabitur rutrum ullamcorper tellus, quis mollis libero efficitur tristique. Cras nec vulputate tellus, quis bibendum augue. Proin id diam vitae libero auctor vehicula. Pellentesque id mauris tincidunt, lacinia massa quis, condimentum dolor. Nam dictum neque non condimentum dignissim. Ut tellus metus, cursus accumsan tincidunt et, tincidunt vitae est.
Aenean sit amet arcu ultrices, tempor urna vel, venenatis quam. Suspendisse nec vehicula nulla, volutpat consectetur est. Etiam id pharetra lorem. Mauris purus lacus, elementum vitae odio sit amet, semper bibendum nisi. Pellentesque arcu turpis, vulputate sit amet viverra non, euismod non mauris. Aenean blandit libero eu mauris accumsan eleifend. Morbi sit amet scelerisque neque. Pellentesque at tristique augue. Aenean aliquet leo in turpis dictum venenatis. Morbi dictum eu dui sit amet sagittis. Ut pretium est sed eros eleifend aliquet. Praesent viverra pulvinar eros ac tincidunt. Fusce facilisis congue urna vitae congue. Donec quis quam sit amet odio laoreet dapibus eu placerat augue.
Nam erat elit, tristique id egestas quis, maximus nec lacus. Aenean finibus bibendum dui malesuada gravida. Nam blandit auctor leo eu elementum. Aliquam id eros a erat scelerisque laoreet vitae quis justo. Donec et tellus velit. Donec hendrerit arcu et rutrum porttitor. Cras venenatis lorem id molestie dignissim. Nullam posuere vitae leo non facilisis. Pellentesque lobortis suscipit auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.lorem

View file

@ -0,0 +1,13 @@
//readfile1.rs
// Make me compile! Execute `rustlings hint readfile1` for hints
use std::fs::File;
fn main() {
let path = "exercises/stdio/dummy.txt";
let file = File::open(path).expect("No file dummy.txt");
let mut s = String::new();
file.read_to_string(&mut s);
println!("{}", s);
}

View file

@ -0,0 +1,14 @@
//readfile1.rs
// How would you read a file without a &mut File.
// Find a suitable type that implements Read and Write trait to read a File.
// Make me compile! Execute `rustlings hint readfile1` for hints
use std::fs::File;
fn main() {
let path = "exercises/stdio/dummy.txt";
let file = File::open(path).expect("No file dummy.txt"); // Don't Change this line.
let mut buf = ???;
file.read_to_string(&mut but);
println!("{}", s);
}

View file

@ -822,3 +822,20 @@ hint = """
The implementation of FromStr should return an Ok with a Person object,
or an Err with a string if the string is not valid.
This is almost like the `try_from_into` exercise."""
[[exercises]]
name = "readfile1"
path = "exercises/stdio/readfile1.rs"
mode = "compile"
hint = """
File implement Read and Write Traits.
Read and Write methods require a &mut File, because of the interfaces for Read and Write
"""
[[exercises]]
name = "readfile2"
path = "exercises/stdio/readfile2.rs"
mode = "compile"
hint = """
BufReader
implements Read and Write traits
"""