Expand description

file_into_string Rust crate

Read a typical text file into a string or vector of strings.

  • file_into_string(file: File) -> std::io::Result<String>

  • file_into_strings(file: File) -> std::io::Result<Vec<String>>


use std::fs::File;
use file_into_string::*;
// Open an existing text file; read the File into a String.
let file = File::open("example.txt").unwrap();
let string = file_into_string(file).unwrap();
// Open an existing text file; read the File into a Vec<String>.
let file = File::open("example.txt").unwrap();
let strings = file_into_strings(file).unwrap();


You can use this Rust crate:

file_into_string = "*"

Or if you prefer, you can copy the source code into your own program.


These functions deliberately preserve line endings, which are \n newlines and \r carriage returns.

These functions use buffered readers for efficiency.

These functions are written to be easy to understand, so you can copy them into your own code if you wish.

If you’re reading very large files, then you may prefer to write your own code to process each line as it’s read.


  • Project: file-into-string-rust-crate
  • Version: 1.1.1
  • Created: 2022-10-01T22:58:34Z
  • Updated: 2022-10-12T21:56:45Z
  • Website: https://github.com/sixarm/file-into-string-rust-crate
  • Contact: Joel Parker Henderson joel@joelparkerhenderson.com
  • License: MIT OR Apache-2.0 OR GPL-2.0 OR GPL-3.0


Read a File into a String.
Read a File into a Vec.