File: fs_write.rs

package info (click to toggle)
rust-tokio 1.48.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,444 kB
  • sloc: makefile: 2
file content (16 lines) | stat: -rw-r--r-- 440 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations

use tempfile::tempdir;
use tokio::fs;

#[tokio::test]
async fn write() {
    let dir = tempdir().unwrap();
    let path = dir.path().join("test.txt");

    fs::write(&path, "Hello, World!").await.unwrap();

    let contents = fs::read_to_string(&path).await.unwrap();
    assert_eq!(contents, "Hello, World!");
}