Function w::fs::read [] [src]

pub fn read<P>(path: P) -> Result<Vec<u8>, Error> where
    P: AsRef<Path>, 
🔬 This is a nightly-only experimental API. (fs_read_write)

Read the entire contents of a file into a bytes vector.

This is a convenience function for using File::open and read_to_end 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.

It will also return an error if it encounters while reading an error of a kind other than ErrorKind::Interrupted.

Examples

#![feature(fs_read_write)]

use std::fs;
use std::net::SocketAddr;

let foo: SocketAddr = String::from_utf8_lossy(&fs::read("address.txt")?).parse()?;