Function oneio::get_reader

source ·
pub fn get_reader(path: &str) -> Result<Box<dyn Read + Send>, OneIoError>
Expand description

Gets a reader for the given file path.

§Arguments

  • path - The path of the file to read.

§Returns

A Result containing a boxed Read+Sync trait object with the file reader, or OneIoError if an error occurs.

§Examples

use std::io::Read;
use oneio::get_reader;

let mut reader = get_reader("file.txt").unwrap();
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).unwrap();
println!("{}", String::from_utf8_lossy(&buffer));