diff options
| author | 2025-01-16 01:26:49 +0800 | |
|---|---|---|
| committer | 2025-01-16 01:26:49 +0800 | |
| commit | ee71943e7433059d9326867d5dd62385ab76ab58 (patch) | |
| tree | 3e96b1343f040212f855a33bcb4ca57dd1f618d4 /src/utils/mod.rs | |
| download | DropOut-ee71943e7433059d9326867d5dd62385ab76ab58.tar.gz DropOut-ee71943e7433059d9326867d5dd62385ab76ab58.zip | |
first commit
Diffstat (limited to 'src/utils/mod.rs')
| -rw-r--r-- | src/utils/mod.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..088da95 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,34 @@ +// utils/mod.rs +pub mod file_utils; +pub mod config_parser; + +// 文件操作相关的实用工具函数 +pub mod file_utils { + use std::fs; + use std::io::{self, Write}; + + pub fn read_file_to_string(path: &str) -> io::Result<String> { + fs::read_to_string(path) + } + + pub fn write_string_to_file(path: &str, content: &str) -> io::Result<()> { + let mut file = fs::File::create(path)?; + file.write_all(content.as_bytes()) + } +} + +// 配置解析相关的实用工具函数 +pub mod config_parser { + use std::collections::HashMap; + + pub fn parse_config(content: &str) -> HashMap<String, String> { + let mut config = HashMap::new(); + for line in content.lines() { + let mut parts = line.splitn(2, '='); + if let (Some(key), Some(value)) = (parts.next(), parts.next()) { + config.insert(key.trim().to_string(), value.trim().to_string()); + } + } + config + } +}
\ No newline at end of file |