Struct MaaInstance

Source
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>

Source

pub fn new(handler: Option<T>) -> Self
where T: CallbackHandler,

Create a new MaaInstance.

§Parameters
  • handler - An optional callback handler for handling Maa events.
Source

pub fn set_option(&self, option: MaaInstOption) -> MaaResult<()>

Source

pub fn bind_resource(&self, res: &MaaResourceInstance<T>) -> MaaResult<()>

Source

pub fn bind_controller( &self, controller: &MaaControllerInstance<T>, ) -> MaaResult<()>

Source

pub fn inited(&self) -> bool

Source

pub fn post_task<P>(&self, entry: &str, param: P) -> MaaTaskResult<'_, T>
where P: TaskParam,

Source

pub fn post_recognition(&self, entry: &str, param: &str) -> MaaTaskResult<'_, T>

Source

pub fn post_action(&self, entry: &str, param: &str) -> MaaTaskResult<'_, T>

Source

pub fn task_all_finished(&self) -> bool

👎Deprecated: Use running instead
Source

pub fn running(&self) -> bool

Source

pub fn post_stop(&self) -> MaaResult<()>

Source

pub fn stop(&self) -> MaaResult<()>

Source

pub fn resource(&self) -> MaaResourceInstance<T>

Source

pub fn controller(&self) -> MaaControllerInstance<T>

Source

pub fn register_custom_recognizer<R>( &mut self, name: &str, recognizer: R, ) -> MaaResult<()>

Available on crate feature custom_recognizer only.
Source

pub fn unregister_custom_recognizer(&mut self, name: &str) -> MaaResult<()>

Available on crate feature custom_recognizer only.
Source

pub fn clear_custom_recognizers(&mut self) -> MaaResult<()>

Available on crate feature custom_recognizer only.
Source

pub fn register_custom_action<A>( &mut self, name: &str, action: A, ) -> MaaResult<()>
where A: MaaCustomAction,

Available on crate feature custom_action only.
Source

pub fn unregister_custom_action(&mut self, name: &str) -> MaaResult<()>

Available on crate feature custom_action only.
Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for MaaInstance<T>

Source§

type Target = *mut MaaInstanceAPI

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> Drop for MaaInstance<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Send for MaaInstance<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.