• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::fs::asyncify;
2 
3 use std::{io, path::Path};
4 
5 /// Creates a future which will open a file for reading and read the entire
6 /// contents into a string and return said string.
7 ///
8 /// This is the async equivalent of [`std::fs::read_to_string`][std].
9 ///
10 /// [std]: fn@std::fs::read_to_string
11 ///
12 /// # Examples
13 ///
14 /// ```no_run
15 /// use tokio::fs;
16 ///
17 /// # async fn dox() -> std::io::Result<()> {
18 /// let contents = fs::read_to_string("foo.txt").await?;
19 /// println!("foo.txt contains {} bytes", contents.len());
20 /// # Ok(())
21 /// # }
22 /// ```
read_to_string(path: impl AsRef<Path>) -> io::Result<String>23 pub async fn read_to_string(path: impl AsRef<Path>) -> io::Result<String> {
24     let path = path.as_ref().to_owned();
25     asyncify(move || std::fs::read_to_string(path)).await
26 }
27