pub struct Context { /* private fields */ }Expand description
Represents the execution context of a task.
This struct provides an interface for interacting with the current task’s runtime state. Capabilities include:
- Executing sub-tasks.
- Overriding pipeline configurations dynamically.
- Performing direct recognition and actions.
- Managing node hit counts and control flow anchors.
§Safety
Context is a wrapper around a non-owning pointer (MaaContext).
The underlying resources are managed by the Tasker. Users must ensure the Context
does not outlive the validity of the underlying task or callback scope.
Implementations§
Source§impl Context
impl Context
Sourcepub fn override_pipeline(&self, override_json: &str) -> MaaResult<()>
pub fn override_pipeline(&self, override_json: &str) -> MaaResult<()>
Overrides pipeline parameters for the current context.
§Arguments
override_json- A JSON string containing the parameters to override.
Sourcepub fn raw(&self) -> *mut MaaContext
pub fn raw(&self) -> *mut MaaContext
Returns the underlying raw MaaContext pointer.
Useful for advanced FFI interop scenarios.
Sourcepub fn run_recognition(
&self,
entry: &str,
pipeline_override: &str,
image: &MaaImageBuffer,
) -> MaaResult<i64>
pub fn run_recognition( &self, entry: &str, pipeline_override: &str, image: &MaaImageBuffer, ) -> MaaResult<i64>
Sourcepub fn run_recognition_direct(
&self,
reco_type: &str,
reco_param: &str,
image: &MaaImageBuffer,
) -> MaaResult<Option<RecognitionDetail>>
pub fn run_recognition_direct( &self, reco_type: &str, reco_param: &str, image: &MaaImageBuffer, ) -> MaaResult<Option<RecognitionDetail>>
Performs a direct recognition operation.
This executes a specific recognition algorithm immediately, bypassing the pipeline structure.
§Arguments
reco_type- The specific recognition algorithm type (e.g., “TemplateMatch”, “OCR”).reco_param- A JSON string containing the recognition parameters.image- The image buffer to perform recognition on.
§Returns
Returns Some(RecognitionDetail) if successful, or None if the operation failed
to initiate or yielded no result.
Sourcepub fn run_action(
&self,
entry: &str,
pipeline_override: &str,
box_rect: &Rect,
reco_detail: &str,
) -> MaaResult<i64>
pub fn run_action( &self, entry: &str, pipeline_override: &str, box_rect: &Rect, reco_detail: &str, ) -> MaaResult<i64>
Runs a specific action with context parameters.
§Arguments
entry- The task entry name.pipeline_override- A JSON string for parameter overrides.box_rect- The target region for the action.reco_detail- A string containing details from a previous recognition step.
§Returns
Returns the job ID associated with the action.
Sourcepub fn run_action_direct(
&self,
action_type: &str,
action_param: &str,
box_rect: &Rect,
reco_detail: &str,
) -> MaaResult<Option<ActionDetail>>
pub fn run_action_direct( &self, action_type: &str, action_param: &str, box_rect: &Rect, reco_detail: &str, ) -> MaaResult<Option<ActionDetail>>
Performs a direct action operation.
This executes a specific action immediately, bypassing the pipeline structure.
§Arguments
action_type- The type of action to perform (e.g., “Click”, “Swipe”).action_param- A JSON string containing the action parameters.box_rect- The target region for the action (e.g., derived from recognition results).reco_detail- Contextual details from a previous recognition step.
§Returns
Returns Some(ActionDetail) on success, or None if the operation failed.
Sourcepub fn override_next(
&self,
node_name: &str,
next_list: &[&str],
) -> MaaResult<bool>
pub fn override_next( &self, node_name: &str, next_list: &[&str], ) -> MaaResult<bool>
Overrides the execution list for a specific node.
§Arguments
node_name- The name of the target node.next_list- A slice of strings representing the new next list. Supports special signals like[JumpBack]and[Anchor].
§Returns
Ok(true)if the override was successful.Ok(false)if the operation failed.
Sourcepub fn get_node_object(
&self,
node_name: &str,
) -> MaaResult<Option<PipelineData>>
pub fn get_node_object( &self, node_name: &str, ) -> MaaResult<Option<PipelineData>>
Sourcepub fn set_anchor(&self, anchor_name: &str, node_name: &str) -> MaaResult<()>
pub fn set_anchor(&self, anchor_name: &str, node_name: &str) -> MaaResult<()>
Associates an anchor with a specific node.
§Arguments
anchor_name- The name of the anchor.node_name- The name of the target node.
Sourcepub fn get_hit_count(&self, node_name: &str) -> MaaResult<u64>
pub fn get_hit_count(&self, node_name: &str) -> MaaResult<u64>
Sourcepub fn clear_hit_count(&self, node_name: &str) -> MaaResult<()>
pub fn clear_hit_count(&self, node_name: &str) -> MaaResult<()>
Resets the hit count for a specific node to zero.
§Arguments
node_name- The name of the node to reset.
Sourcepub fn clone_context(&self) -> MaaResult<Self>
pub fn clone_context(&self) -> MaaResult<Self>
Creates a clone of the current context.
The new context can be used for independent execution threads, preventing state interference with the original context.
Sourcepub fn tasker_handle(&self) -> *mut MaaTasker
pub fn tasker_handle(&self) -> *mut MaaTasker
Returns the raw handle to the associated Tasker instance.
§Safety
The returned pointer is owned by the framework. The caller must not attempt to destroy or free it.
Sourcepub fn override_image(
&self,
image_name: &str,
image: &MaaImageBuffer,
) -> MaaResult<()>
pub fn override_image( &self, image_name: &str, image: &MaaImageBuffer, ) -> MaaResult<()>
Overrides a global image resource with a provided buffer.
§Arguments
image_name- The identifier of the image to override.image- The new image data buffer.
Sourcepub fn get_task_job<'a>(&'a self) -> JobWithResult<'a, TaskDetail>
pub fn get_task_job<'a>(&'a self) -> JobWithResult<'a, TaskDetail>
Retrieves a job handle representing the current task’s execution state.
The returned job is bound to the lifetime of the Context to ensure safety.
Sourcepub fn clear_all_hit_counts(&self) -> MaaResult<()>
pub fn clear_all_hit_counts(&self) -> MaaResult<()>
Resets hit counts for all nodes in the context.
This clears the execution history for all nodes, resetting their hit counts to zero.