pub struct MaaInstance<T> { /* private fields */ }
Expand description
The MaaInstance struct is the main entry point for the Maa library.
It is used to create and manage the Maa instance for running tasks.
§Example
use maa_framework::instance::MaaInstance;
let instance = MaaInstance::new(None);
// let param = serde_json::json!({"param": "value"});
// instance.post_task("task", param).await;
§Note
MaaInstance, MaaResourceInstance and MaaControllerInstance use the same mechanism to manage the lifetime of the underlying C++ object.
That is, if the object is created from the Rust code (like MaaInstance::new
), the object will be destroyed when it goes out of scope. In this case, it is your responsibility to ensure that the object is not used after it has been destroyed.
If the object is created from the C++ code, then you will not have to worry about the lifetime of the object.
Implementations§
Source§impl<T> MaaInstance<T>
impl<T> MaaInstance<T>
Sourcepub fn new(handler: Option<T>) -> Selfwhere
T: CallbackHandler,
pub fn new(handler: Option<T>) -> Selfwhere
T: CallbackHandler,
Create a new MaaInstance.
§Parameters
handler
- An optional callback handler for handling Maa events.
pub fn set_option(&self, option: MaaInstOption) -> MaaResult<()>
pub fn bind_resource(&self, res: &MaaResourceInstance<T>) -> MaaResult<()>
pub fn bind_controller( &self, controller: &MaaControllerInstance<T>, ) -> MaaResult<()>
pub fn inited(&self) -> bool
pub fn post_task<P>(&self, entry: &str, param: P) -> MaaTaskResult<'_, T>where
P: TaskParam,
pub fn post_recognition(&self, entry: &str, param: &str) -> MaaTaskResult<'_, T>
pub fn post_action(&self, entry: &str, param: &str) -> MaaTaskResult<'_, T>
pub fn task_all_finished(&self) -> bool
👎Deprecated: Use
running
insteadpub fn running(&self) -> bool
pub fn post_stop(&self) -> MaaResult<()>
pub fn stop(&self) -> MaaResult<()>
pub fn resource(&self) -> MaaResourceInstance<T>
pub fn controller(&self) -> MaaControllerInstance<T>
pub fn register_custom_recognizer<R>(
&mut self,
name: &str,
recognizer: R,
) -> MaaResult<()>where
R: MaaCustomRecognizer,
Available on crate feature
custom_recognizer
only.pub fn unregister_custom_recognizer(&mut self, name: &str) -> MaaResult<()>
Available on crate feature
custom_recognizer
only.pub fn clear_custom_recognizers(&mut self) -> MaaResult<()>
Available on crate feature
custom_recognizer
only.pub fn register_custom_action<A>(
&mut self,
name: &str,
action: A,
) -> MaaResult<()>where
A: MaaCustomAction,
Available on crate feature
custom_action
only.pub fn unregister_custom_action(&mut self, name: &str) -> MaaResult<()>
Available on crate feature
custom_action
only.pub fn clear_custom_actions(&mut self) -> MaaResult<()>
Available on crate feature
custom_action
only.Trait Implementations§
Source§impl<T: Debug> Debug for MaaInstance<T>
impl<T: Debug> Debug for MaaInstance<T>
Source§impl<T> Deref for MaaInstance<T>
impl<T> Deref for MaaInstance<T>
Source§impl<T> Drop for MaaInstance<T>
impl<T> Drop for MaaInstance<T>
impl<T> Send for MaaInstance<T>
impl<T> Sync for MaaInstance<T>
Auto Trait Implementations§
impl<T> Freeze for MaaInstance<T>
impl<T> RefUnwindSafe for MaaInstance<T>where
T: RefUnwindSafe,
impl<T> Unpin for MaaInstance<T>where
T: Unpin,
impl<T> UnwindSafe for MaaInstance<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more