Function save_string_to_file

Source
pub fn save_string_to_file<P: AsRef<Path>>(content: &str, path: P)
Expand description

Saves a string to a file at the specified path.

§Arguments

  • content - The string content to save to the file.
  • path - The path where the file should be saved (can be a &str, String, Path, or PathBuf).

§Panics

If some error is encountered while creating the file or writing to it.

§Note

This function will create the parent folder for the file if it does not already exist.

§Examples

§Using a string literal

use file_io::save_string_to_file;

let content: &str = "Hello, world!";
let path: &str = "folder/subfolder_11/file_6.txt";

save_string_to_file(content, path);

§Using a Path reference

use file_io::save_string_to_file;
use std::path::Path;

let content: &str = "Hello, world!";
let path: &Path = Path::new("folder/subfolder_12/file_7.txt");

save_string_to_file(content, path);