Files
rustdesk/libs/flutter_rust_bridge_codegen/src/utils.rs
2022-05-31 16:28:12 +08:00

27 lines
652 B
Rust

use std::fs;
use std::path::Path;
pub fn mod_from_rust_path(code_path: &str, crate_path: &str) -> String {
Path::new(code_path)
.strip_prefix(Path::new(crate_path).join("src"))
.unwrap()
.with_extension("")
.into_os_string()
.into_string()
.unwrap()
.replace('/', "::")
}
pub fn with_changed_file<F: FnOnce() -> anyhow::Result<()>>(
path: &str,
append_content: &str,
f: F,
) -> anyhow::Result<()> {
let content_original = fs::read_to_string(&path)?;
fs::write(&path, content_original.clone() + append_content)?;
f()?;
Ok(fs::write(&path, content_original)?)
}