pub struct Resource { /* private fields */ }Implementations§
Source§impl Resource
impl Resource
Sourcepub fn register_custom_action(
&self,
name: &str,
action: Box<dyn CustomAction>,
) -> MaaResult<()>
pub fn register_custom_action( &self, name: &str, action: Box<dyn CustomAction>, ) -> MaaResult<()>
Register a custom action implementation.
The action will be kept alive as long as it is registered in the Resource.
The framework rejects an empty name and any name already taken by a custom
recognition or action on this Resource; in that case the previous registration is
kept and Err(MaaError::InvalidArgument) is returned. Unregister first to replace.
Sourcepub fn register_custom_recognition(
&self,
name: &str,
reco: Box<dyn CustomRecognition>,
) -> MaaResult<()>
pub fn register_custom_recognition( &self, name: &str, reco: Box<dyn CustomRecognition>, ) -> MaaResult<()>
Register a custom recognition implementation.
The recognizer will be kept alive as long as it is registered in the Resource.
The framework rejects an empty name and any name already taken by a custom
recognition or action on this Resource; in that case the previous registration is
kept and Err(MaaError::InvalidArgument) is returned. Unregister first to replace.
Source§impl Resource
impl Resource
Sourcepub unsafe fn from_raw(ptr: *mut MaaResource) -> MaaResult<Self>
pub unsafe fn from_raw(ptr: *mut MaaResource) -> MaaResult<Self>
Create a Resource from a raw pointer, taking ownership.
§Safety
The pointer must be valid and the caller transfers ownership to the Resource.
The Resource will call MaaResourceDestroy when dropped.
Sourcepub fn post_bundle(&self, path: &str) -> MaaResult<ResJob>
pub fn post_bundle(&self, path: &str) -> MaaResult<ResJob>
Load a resource bundle from the specified directory.
The bundle should contain pipeline definitions, images, and models.
Sourcepub fn raw(&self) -> *mut MaaResource
pub fn raw(&self) -> *mut MaaResource
Get the raw resource handle.
Sourcepub fn post_ocr_model(&self, path: &str) -> MaaResult<ResJob>
pub fn post_ocr_model(&self, path: &str) -> MaaResult<ResJob>
Load an OCR model from the specified directory.
Sourcepub fn post_pipeline(&self, path: &str) -> MaaResult<ResJob>
pub fn post_pipeline(&self, path: &str) -> MaaResult<ResJob>
Load additional pipeline definitions from the specified directory.
Sourcepub fn post_image(&self, path: &str) -> MaaResult<ResJob>
pub fn post_image(&self, path: &str) -> MaaResult<ResJob>
Load image resources from the specified directory.
Sourcepub fn override_pipeline(&self, pipeline_override: &str) -> MaaResult<()>
pub fn override_pipeline(&self, pipeline_override: &str) -> MaaResult<()>
Override pipeline parameters with a JSON string.
Sourcepub fn override_pipeline_json(&self, pipeline_override: &Value) -> MaaResult<()>
pub fn override_pipeline_json(&self, pipeline_override: &Value) -> MaaResult<()>
Sourcepub fn override_next(
&self,
node_name: &str,
next_list: &[&str],
) -> MaaResult<()>
pub fn override_next( &self, node_name: &str, next_list: &[&str], ) -> MaaResult<()>
Override the next node list for a specific node.
§Arguments
node_name- The name of the node to modifynext_list- The new list of next nodes
Sourcepub fn get_node_data(&self, node_name: &str) -> MaaResult<Option<String>>
pub fn get_node_data(&self, node_name: &str) -> MaaResult<Option<String>>
Get node data as a JSON string.
Sourcepub fn get_node_object(
&self,
node_name: &str,
) -> MaaResult<Option<PipelineData>>
pub fn get_node_object( &self, node_name: &str, ) -> MaaResult<Option<PipelineData>>
Get node data as a deserialized PipelineData object.
Sourcepub fn node_list(&self) -> MaaResult<Vec<String>>
pub fn node_list(&self) -> MaaResult<Vec<String>>
Get a list of all node names in the loaded pipelines.
Sourcepub fn hash(&self) -> MaaResult<String>
pub fn hash(&self) -> MaaResult<String>
Get a hash of the loaded resources for cache validation.
Sourcepub fn get_default_recognition_param(
&self,
reco_type: &str,
) -> MaaResult<Option<Value>>
pub fn get_default_recognition_param( &self, reco_type: &str, ) -> MaaResult<Option<Value>>
Get valid default parameters for a recognition type as JSON.
§Arguments
reco_type- The recognition type (e.g. “TemplateMatch”, “OCR”).
Sourcepub fn get_default_action_param(
&self,
action_type: &str,
) -> MaaResult<Option<Value>>
pub fn get_default_action_param( &self, action_type: &str, ) -> MaaResult<Option<Value>>
Get valid default parameters for an action type as JSON.
§Arguments
action_type- The action type (e.g. “Click”, “Swipe”).
Sourcepub fn use_directml(&self, device_id: i32) -> MaaResult<()>
pub fn use_directml(&self, device_id: i32) -> MaaResult<()>
Use DirectML for GPU-accelerated inference (Windows only).
§Arguments
device_id- GPU device index (0 for first GPU)
Sourcepub fn use_webgpu(&self, device_id: i32) -> MaaResult<()>
pub fn use_webgpu(&self, device_id: i32) -> MaaResult<()>
Use WebGPU for GPU-accelerated inference (Windows, Linux and macOS).
§Arguments
device_id- WebGPU device id (0 for the first device)
Sourcepub fn use_ncnn(&self) -> MaaResult<()>
pub fn use_ncnn(&self) -> MaaResult<()>
Use NCNN for inference (Android builds only, CPU only).
Fails on builds without NCNN, and when switching to or from NCNN after
resource loading has started (until clear).
Models are loaded from <model stem>.ncnn.param/.ncnn.bin/.ncnn.json
with no fallback to onnxruntime.
Sourcepub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
pub fn add_sink<F>(&self, callback: F) -> MaaResult<MaaSinkId>
Register a raw callback to receive events.
The callback receives event type and details as JSON strings.
Sourcepub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
pub fn add_event_sink(&self, sink: Box<dyn EventSink>) -> MaaResult<MaaSinkId>
Register a strongly-typed event sink.
This method registers an implementation of the EventSink trait
to receive structured notifications from this resource.
§Arguments
sink- The event sink implementation (must be boxed).
§Returns
A MaaSinkId which can be used to manually remove the sink later via remove_sink.
The sink will be automatically unregistered and dropped when the Resource is dropped.
Sourcepub fn remove_sink(&self, sink_id: MaaSinkId)
pub fn remove_sink(&self, sink_id: MaaSinkId)
Remove a previously registered event sink.
Sourcepub fn clear_sinks(&self)
pub fn clear_sinks(&self)
Remove all registered event sinks.
Sourcepub fn override_image(
&self,
image_name: &str,
image: &MaaImageBuffer,
) -> MaaResult<()>
pub fn override_image( &self, image_name: &str, image: &MaaImageBuffer, ) -> MaaResult<()>
Override an image resource at runtime.
§Arguments
image_name- The name of the image to overrideimage- The new image buffer to use
Sourcepub fn use_auto_ep(&self) -> MaaResult<()>
pub fn use_auto_ep(&self) -> MaaResult<()>
Auto-select the best inference execution provider.
Tries CUDA, then DirectML, then WebGPU, then CoreML, and falls back to CPU.
Sourcepub fn use_coreml(&self, coreml_flag: i32) -> MaaResult<()>
👎Deprecated: MaaDeps no longer ships CoreML; use use_webgpu instead
pub fn use_coreml(&self, coreml_flag: i32) -> MaaResult<()>
MaaDeps no longer ships CoreML; use use_webgpu instead
Use CoreML for inference (macOS only).
MaaDeps no longer ships the CoreML execution provider since MaaFramework 5.14.3.
§Arguments
coreml_flag- CoreML configuration flag
Sourcepub fn use_cuda(&self, nvidia_gpu_id: i32) -> MaaResult<()>
pub fn use_cuda(&self, nvidia_gpu_id: i32) -> MaaResult<()>
Use CUDA for inference (NVIDIA GPU only).
§Arguments
nvidia_gpu_id- NVIDIA GPU device ID (typically 0 for first GPU)
Sourcepub fn unregister_custom_recognition(&self, name: &str) -> MaaResult<()>
pub fn unregister_custom_recognition(&self, name: &str) -> MaaResult<()>
Unregister a custom recognition by name.
Sourcepub fn unregister_custom_action(&self, name: &str) -> MaaResult<()>
pub fn unregister_custom_action(&self, name: &str) -> MaaResult<()>
Unregister a custom action by name.
Sourcepub fn custom_recognition_list(&self) -> MaaResult<Vec<String>>
pub fn custom_recognition_list(&self) -> MaaResult<Vec<String>>
Get the list of registered custom recognitions.
Sourcepub fn custom_action_list(&self) -> MaaResult<Vec<String>>
pub fn custom_action_list(&self) -> MaaResult<Vec<String>>
Get the list of registered custom actions.
Sourcepub fn clear_custom_recognition(&self) -> MaaResult<()>
pub fn clear_custom_recognition(&self) -> MaaResult<()>
Clear all registered custom recognitions.
Sourcepub fn clear_custom_action(&self) -> MaaResult<()>
pub fn clear_custom_action(&self) -> MaaResult<()>
Clear all registered custom actions.