1#![no_std]
2
3#[cfg(feature = "std")]
4extern crate std;
5
6mod proto_files;
7pub use proto_files::PROTO_FILES;
8
9#[cfg(feature = "std")]
11pub fn write_proto(target_dir: &std::path::Path) -> Result<(), std::string::String> {
12 use std::{
13 format,
14 fs::{self, File},
15 io::Write,
16 string::ToString,
17 };
18
19 if !target_dir.exists() {
20 fs::create_dir_all(target_dir).map_err(|err| format!("Error creating directory: {err}"))?;
21 } else if !target_dir.is_dir() {
22 return Err("The target path exists but is not a directory".to_string());
23 }
24
25 for (file_name, file_content) in PROTO_FILES {
26 let mut file_path = target_dir.to_path_buf();
27 file_path.push(file_name);
28 let mut file =
29 File::create(&file_path).map_err(|err| format!("Error creating {file_name}: {err}"))?;
30 file.write_all(file_content.as_bytes())
31 .map_err(|err| format!("Error writing {file_name}: {err}"))?;
32 }
33
34 Ok(())
35}