-
Notifications
You must be signed in to change notification settings - Fork 334
feat: 新增 Rust binding by AI #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| [package] | ||
| name = "maa-framework" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["MaaFramework Contributors"] | ||
| description = "Rust bindings for MaaFramework" | ||
| license = "MIT" | ||
| repository = "https://github.com/MaaAssistantArknights/MaaFramework" | ||
| keywords = ["maa", "automation", "framework", "binding"] | ||
| categories = ["api-bindings", "development-tools"] | ||
|
|
||
| [dependencies] | ||
| libloading = "0.8" | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| serde_json = "1.0" | ||
| thiserror = "1.0" | ||
| image = { version = "0.24", optional = true } | ||
|
|
||
| [features] | ||
| default = [] | ||
| image = ["dep:image"] | ||
|
|
||
| [dev-dependencies] | ||
| tokio = { version = "1.0", features = ["full"] } | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,253 @@ | ||||||
| # MaaFramework Rust Binding | ||||||
|
|
||||||
| MaaFramework 的 Rust 语言绑定。 | ||||||
|
|
||||||
| > ⚠️ **Warning**: This binding was entirely generated by AI and has not been thoroughly tested. Developers should verify its correctness and stability before use. Use at your own risk. | ||||||
| > | ||||||
| > ⚠️ **注意**:此绑定完全由 AI 生成,尚未经过充分测试。请开发者在使用时自行验证其正确性和稳定性。 | ||||||
|
|
||||||
| ## 安装 | ||||||
|
|
||||||
| 在 `Cargo.toml` 中添加依赖: | ||||||
|
|
||||||
| ```toml | ||||||
| [dependencies] | ||||||
| maa-framework = { path = "path/to/binding/Rust" } | ||||||
| ``` | ||||||
|
|
||||||
| ## 使用示例 | ||||||
|
|
||||||
| ### 基本使用 | ||||||
|
|
||||||
| ```rust | ||||||
| use maa_framework::*; | ||||||
| use serde_json::json; | ||||||
|
|
||||||
| fn main() -> Result<()> { | ||||||
| // 加载动态库 | ||||||
| load_library("path/to/MaaFramework.dll")?; | ||||||
| load_toolkit("path/to/MaaToolkit.dll")?; | ||||||
|
|
||||||
| // 设置全局选项 | ||||||
| set_log_dir("./log"); | ||||||
| set_debug_mode(true); | ||||||
|
|
||||||
| // 查找 ADB 设备 | ||||||
| let devices = Toolkit::find_adb_devices(); | ||||||
| if devices.is_empty() { | ||||||
| println!("未找到设备"); | ||||||
| return Ok(()); | ||||||
| } | ||||||
|
|
||||||
| let device = &devices[0]; | ||||||
| println!("找到设备: {} - {}", device.name, device.address); | ||||||
|
|
||||||
| // 创建控制器 | ||||||
| let controller = AdbController::new( | ||||||
| &device.adb_path, | ||||||
| &device.address, | ||||||
| adb_screencap_method::DEFAULT, | ||||||
| adb_input_method::DEFAULT, | ||||||
| &device.config, | ||||||
| "path/to/MaaAgentBinary", | ||||||
| )?; | ||||||
|
|
||||||
| // 连接设备 | ||||||
| controller.post_connection().wait(); | ||||||
| if !controller.connected() { | ||||||
| return Err(MaaError::ConnectionFailed); | ||||||
| } | ||||||
|
|
||||||
| // 创建资源 | ||||||
| let resource = Resource::new()?; | ||||||
| resource.post_bundle("path/to/resource").wait(); | ||||||
| if !resource.loaded() { | ||||||
| return Err(MaaError::ResourceLoadFailed); | ||||||
| } | ||||||
|
|
||||||
| // 创建任务器 | ||||||
| let mut tasker = Tasker::new()?; | ||||||
| tasker.bind(resource, controller.inner.clone()); | ||||||
|
||||||
| tasker.bind(resource, controller.inner.clone()); | |
| tasker.bind(resource, controller); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error propagation operator in the example. The same compilation issue exists here -
post_connection()returnsResult<CtrlJob>, notCtrlJob, so.wait()cannot be called directly.Should be:
This pattern is repeated throughout the examples in lines 56, 63, 116, 130-147.