std::fs::read_string - Rust
Description: API documentation for the Rust `read_string` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, read_string

# Function std::fs::read_string [−] [src]

    pub fn read_string<P: AsRef<Path>>(path: P) -> Result<String>

🔬 This is a nightly-only experimental API. (`fs_read_write` #46588)

Read 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`.

It will also return an error if it encounters while reading an error of a kind other than `ErrorKind::Interrupted`, or if the contents of the file are not valid UTF-8.

# Examples

    #![feature(fs_read_write)]

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

    let foo: SocketAddr = fs::read_string("address.txt")?.parse()?;Run

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)