hermes_tokio_runtime_components/impls/fs/
write_file.rs

1use std::io::Error as IoError;
2use std::path::Path;
3
4use cgp::prelude::*;
5use hermes_runtime_components::traits::fs::file_path::HasFilePathType;
6use hermes_runtime_components::traits::fs::write_file::StringToFileWriter;
7use tokio::fs::write;
8
9pub struct TokioWriteStringToFile;
10
11impl<Runtime> StringToFileWriter<Runtime> for TokioWriteStringToFile
12where
13    Runtime: HasFilePathType + HasErrorType,
14    Runtime::FilePath: AsRef<Path>,
15    Runtime: CanRaiseError<IoError>,
16{
17    async fn write_string_to_file(
18        _runtime: &Runtime,
19        path: &Runtime::FilePath,
20        content: &str,
21    ) -> Result<(), Runtime::Error> {
22        write(path, content).await.map_err(Runtime::raise_error)?;
23
24        Ok(())
25    }
26}