2 stable releases

Uses old Rust 2015

1.0.1 Oct 6, 2017

#1190 in Filesystem

Download history 97/week @ 2024-04-16 319/week @ 2024-04-23 148/week @ 2024-04-30 201/week @ 2024-05-07 192/week @ 2024-05-14 310/week @ 2024-05-21 256/week @ 2024-05-28 352/week @ 2024-06-04 281/week @ 2024-06-11 276/week @ 2024-06-18 195/week @ 2024-06-25 196/week @ 2024-07-02 241/week @ 2024-07-09 120/week @ 2024-07-16 238/week @ 2024-07-23 116/week @ 2024-07-30

766 downloads per month
Used in 6 crates (3 directly)

Unlicense

7KB

slurp

some little helper functions to load files without the boilerplate Build Status Build status

slurp exists to solve a very particular problem. If you're trying to load a file from disk, there's some boilerplate code that you need to write up to handle the Read trait effectively:

// gotta declare the output before??
let mut buf = String::new();
// gotta declare the file reader separately??
let mut file = File::open(filename).unwrap();

file.read_to_string(&mut buf).unwrap();

Now, there's a really good reason Read doesn't allocate its own Vecs or Strings: This way, you can really easily reuse your own buffers. But what if you want to hang onto each file's contents separately? Or what if you're only loading one file ever? All this extra ability just gets in the way when you just want to slurp a file off the disk.

That's where this crate comes in! By adding this crate (or copying its functions into your project - they're really quite small), all that boilerplate gets wrapped away into its own function!

let my_file = slurp::read_all_to_string(filename).unwrap();

slurp also contains other functions to load into a byte vector (read_all_bytes) or into a Vec with one String for each line (read_all_lines).

To use this crate in your project, add the following to your Cargo.toml:

[dependencies]
slurp = "1.0.1"

...and the following in your crate root:

extern crate slurp;

License

slurp is licensed under the Unlicense, which is effectively a public domain dedication. If you don't want to add an entirely separate crate for this, feel free to copy the code into your own project!

No runtime deps