safe_write

Function safe_write 

Source
pub fn safe_write(path: &Path, content: &str) -> Result<()>
Expand description

Safely writes a string to a file using atomic operations.

This is a convenience wrapper around atomic_write that handles string-to-bytes conversion. The write is atomic, meaning the file either contains the new content or the old content, never a partial write.

§Arguments

  • path - The file path to write to
  • content - The string content to write

§Returns

  • Ok(()) if the file was written successfully
  • Err if the write operation fails

§Examples

use agpm_cli::utils::fs::safe_write;
use std::path::Path;

safe_write(Path::new("config.toml"), "[sources]\ncommunity = \"https://example.com\"")?;

§See Also