diff --git a/exercises/stdio/README.md b/exercises/stdio/README.md new file mode 100644 index 0000000..d278290 --- /dev/null +++ b/exercises/stdio/README.md @@ -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) diff --git a/exercises/stdio/dummy.txt b/exercises/stdio/dummy.txt new file mode 100644 index 0000000..6fc15c7 --- /dev/null +++ b/exercises/stdio/dummy.txt @@ -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 \ No newline at end of file diff --git a/exercises/stdio/readfile1.rs b/exercises/stdio/readfile1.rs new file mode 100644 index 0000000..315a102 --- /dev/null +++ b/exercises/stdio/readfile1.rs @@ -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); +} diff --git a/exercises/stdio/readfile2.rs b/exercises/stdio/readfile2.rs new file mode 100644 index 0000000..2760600 --- /dev/null +++ b/exercises/stdio/readfile2.rs @@ -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); +} diff --git a/info.toml b/info.toml index 46e353f..2fbf6a1 100644 --- a/info.toml +++ b/info.toml @@ -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 +""" \ No newline at end of file