Crate slurp [−] [src]
A collection of convenience methods around loading files into various containers.
This crate contains a few small wrapper methods around common operations in the standard
library for loading files. The Read
trait is a little cumbersome if you don't want to bother
keeping up with a buffer, or if you're only loading one file. Here, you can wrap up all that
boilerplate into little one-off functions!
To read a file into a string:
let my_file = slurp::read_all_to_string("myfile.txt").unwrap();
To read a file into a byte vector:
let my_file = slurp::read_all_bytes("myfile.txt").unwrap();
Or, to read a file into a Vec where each element is a different line:
let my_file: Vec<String> = slurp::read_all_lines("myfile.txt").unwrap();
There's also an iterator to lazily load the lines, though it's mainly a wrapper over
io::BufReader
:
for line in slurp::iterate_all_lines("myfile.txt") { let line = line.unwrap(); }
Structs
Lines |
Iterator over the lines of a file. |
Functions
iterate_all_lines |
Returns an iterator over the lines in the file at the given filename. |
read_all_bytes |
Reads the file at the given filename into a new byte vector. |
read_all_lines |
Reads the lines of the file at the given filename into a new collection of Strings. |
read_all_to_string |
Reads the file at the given filename into a new String. |