首次提交
This commit is contained in:
27
src/lib.rs
Normal file
27
src/lib.rs
Normal 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))
|
||||
}
|
||||
Reference in New Issue
Block a user