Function oneio::read_to_string

source ·
pub fn read_to_string(path: &str) -> Result<String, OneIoError>
Expand description

Reads the contents of a file to a string.

§Arguments

  • path - A string slice that represents the path to the file.

§Returns

  • Result<String, OneIoError> - A Result where the Ok variant contains the contents of the file as a string if the file was successfully read, or the Err variant contains a OneIoError if an I/O error occurred.

§Examples

use std::fs::File;
use oneio::read_to_string;

let path = "path/to/file.txt";
let result = read_to_string(path);
match result {
    Ok(content) => println!("File content: {}", content),
    Err(error) => eprintln!("Error: {}", error),
}