A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/nightly/std/fs/fn.read_to_string.html below:

read_to_string in std::fs - Rust

Function read_to_string1.26.0 · Source
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String>
Expand description

Reads the entire contents of a file into a string.

This is a convenience function for using File::open and read_to_string with fewer imports and without an intermediate variable.

§Errors

This function will return an error if path does not already exist. Other errors may also be returned according to OpenOptions::open.

If the contents of the file are not valid UTF-8, then an error will also be returned.

While reading from the file, this function handles io::ErrorKind::Interrupted with automatic retries. See io::Read documentation for details.

§Examples
use std::fs;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let message: String = fs::read_to_string("message.txt")?;
    println!("{}", message);
    Ok(())
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4