首次提交

This commit is contained in:
2026-01-23 13:43:18 +08:00
commit 677681e0f3
11 changed files with 1701 additions and 0 deletions

27
src/lib.rs Normal file
View File

@@ -0,0 +1,27 @@
use tokio::runtime::Runtime;
mod network;
#[cxx::bridge]
mod ffi {
extern "Rust" {
fn download_file(url: &str, path: &str) -> Result<()>;
fn http_get(url: &str) -> Result<String>;
}
}
fn get_runtime() -> Runtime {
Runtime::new().expect("创建Tokio运行时失败")
}
fn download_file(url: &str, path: &str) -> Result<(), Box<dyn std::error::Error>> {
let rt = get_runtime();
rt.block_on(network::download_file(url, path))?;
Ok(())
}
fn http_get(url: &str) -> Result<String, Box<dyn std::error::Error>> {
let rt = get_runtime();
rt.block_on(network::http_get(url))
}