Common/FileSystem/
WriteFileString.rs

1//! # WriteFileString Effect
2//!
3//! Defines a convenience `ActionEffect` for writing string content to a file.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::WriteFileBytes::WriteFileBytes;
8use crate::{
9	Effect::ActionEffect::ActionEffect,
10	Error::CommonError::CommonError,
11	FileSystem::FileSystemWriter::FileSystemWriter,
12};
13
14/// Creates a convenience effect that writes string content to a file.
15///
16/// This function is a wrapper around `WriteFileBytes`. It first converts the
17/// provided `String` into a byte vector (`Vec<u8>`) and then delegates to the
18/// `WriteFileBytes` effect constructor. This simplifies call sites that are
19/// working with text data.
20///
21/// # Parameters
22/// * `Path`: The `PathBuf` of the file to write to.
23/// * `Content`: The `String` content to be written.
24/// * `Create`: If `true`, the file will be created if it does not exist.
25/// * `Overwrite`: If `true`, an existing file will be overwritten.
26///
27/// # Returns
28/// An `ActionEffect` that resolves to `()` on success and requires the
29/// `FileSystemWriter` capability.
30pub fn WriteFileString(
31	Path:PathBuf,
32
33	Content:String,
34
35	Create:bool,
36
37	Overwrite:bool,
38) -> ActionEffect<Arc<dyn FileSystemWriter>, CommonError, ()> {
39	WriteFileBytes(Path, Content.into_bytes(), Create, Overwrite)
40}