1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
//! > **Rust bindings for MaaFramework**
//!
//! This crate provides Rust bindings for [MaaFramework](https://github.com/MaaAssistantArknights/MaaFramework).
//! On top of the raw bindings generated by bindgen, we provide a safe and more rust-friendly wrapper for use.
//!
//! ## Pre-requisites
//!
//! This crate utilizes cmake to find and link to the MaaFramework library. You will need to have cmake installed on your system and make sure that MaaFramework is installed in a place where cmake can find it.
//! In addition, you will also need the MaaFramework library installed on your system to run any tests or binaries that use this crate.
//!
//! ## Usage
//!
//! Refer to the concerning struct for usage examples. Furthermore, you should check the MaaFramework repo to get a more in-depth understanding of the API.
//!
//! If you have no idea where to start, you can check the [instance] module for starter.
//!
//! ## Features
//!
//! - `internal`: Enable internal API for MaaFramework. This enables you to directly access the raw bindings.
//! - `toolkit`: Enable MaaToolkit.
//! - `sync_context`: Enable sync context for MaaFramework.
//! - `adb`: Enable adb controller for MaaFramework.
//! - `win32`: Enable win32 controller for MaaFramework.
//! - `dbg`: Enable debug controller for MaaFramework. This is most likely not needed.
//! - `custom_recognizer`: Enable custom recognizer for MaaFramework.
//! - `custom_controller`: Enable custom controller for MaaFramework.
//! - `custom_action`: Enable custom action for MaaFramework.
//! - `custom`: Enable all custom features for MaaFramework.
//!
//! The default features include all features so you might want to disable some of them if you don't need them.
#![feature(doc_cfg)]
use msg::MaaMsg;
use serde::{Deserialize, Serialize};
#[cfg(feature = "internal")]
#[doc(cfg(feature = "internal"))]
pub mod internal;
#[cfg(not(feature = "internal"))]
mod internal;
#[cfg(feature = "toolkit")]
#[doc(cfg(feature = "toolkit"))]
pub mod toolkit;
pub mod custom;
#[cfg(feature = "sync_context")]
#[doc(cfg(feature = "sync_context"))]
pub mod sync_context;
pub mod buffer;
pub mod controller;
pub mod diff_task;
pub mod error;
pub mod instance;
pub mod msg;
pub mod resource;
pub mod utility;
use error::Error;
pub type MaaResult<T> = Result<T, error::Error>;
#[derive(Debug, Serialize, Deserialize)]
pub enum MaaStatus {
Invalid,
Pending,
Running,
Success,
Failed,
}
impl TryFrom<internal::MaaStatus> for MaaStatus {
type Error = error::Error;
fn try_from(status: internal::MaaStatus) -> Result<Self, Self::Error> {
match status {
internal::MaaStatusEnum_MaaStatus_Invalid => Ok(MaaStatus::Invalid),
internal::MaaStatusEnum_MaaStatus_Pending => Ok(MaaStatus::Pending),
internal::MaaStatusEnum_MaaStatus_Running => Ok(MaaStatus::Running),
internal::MaaStatusEnum_MaaStatus_Success => Ok(MaaStatus::Success),
internal::MaaStatusEnum_MaaStatus_Failed => Ok(MaaStatus::Failed),
_ => Err(error::Error::MaaStatusConversionError(status)),
}
}
}
/// The callback handler trait.
///
/// This trait is used to handle the callback from MaaFramework.
pub trait CallbackHandler {
fn handle(&mut self, msg: MaaMsg);
}
pub fn maa_version() -> String {
let version = unsafe { internal::MaaVersion() };
string!(version)
}