title | timestamp | author | published | description | tags | ||
---|---|---|---|---|---|---|---|
Slurp: read content of a text file into a string |
2023-11-22 02:30:01 -0800 |
szabgab |
true |
Read the content of a file into memory in one short function call. |
|
People who programmed in Perl are probably familiar with what was called slurp mode that was later converted to a function called slurp. The whole idea was to make it easy to read the content of a text file into memory, to slurp it in.
In Rust there is a function called read_to_string that does this.
{% include file="examples/slurp/src/main.rs" %}
It is nice and easy to use, you just have to remember that this will read the whole file into memory which is not going to work well for huge files.