| Crates.io | openharmony-ability-derive |
| lib.rs | openharmony-ability-derive |
| version | 0.2.2 |
| created_at | 2025-01-24 06:15:05.383069+00 |
| updated_at | 2025-08-21 02:17:36.085678+00 |
| description | Binding Rust application macro on Harmony with Ability |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1529086 |
| size | 11,307 |
openharmony-ability-derive is a macro crate for the openharmony-ability project. It provides a macro for generating code to accept the OpenHarmony/HarmonyNext ability's lifecycle callbacks.
cargo add openharmony-ability-derive
We support two different mode to render.
Using XComponent to render code that can use OpenGL or Vulkan.
Example
use openharmony_ability_derive::ability;
#[ability]
fn openharmony_app(app: OpenHarmonyApp) {
app.run_loop(|types| match types {
Event::Input(k) => match k {
InputEvent::TextInputEvent(s) => {
hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
}
_ => {
hilog_info!(format!("ohos-rs macro input:").as_str());
}
},
Event::WindowRedraw(_) => {}
_ => {
hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
}
});
}
Using ArkWeb to render everything.
Example
use openharmony_ability_derive::ability;
#[ability(webview)]
fn openharmony_app(app: OpenHarmonyApp) {
app.run_loop(|types| match types {
Event::Input(k) => match k {
InputEvent::TextInputEvent(s) => {
hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
}
_ => {
hilog_info!(format!("ohos-rs macro input:").as_str());
}
},
Event::WindowRedraw(_) => {}
_ => {
hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
}
});
}
And we also support custom protocols. Just add them into ability:
use openharmony_ability_derive::ability;
#[ability(webview, protocol = "custom,hello")]
fn openharmony_app(app: OpenHarmonyApp) {
app.run_loop(|types| match types {
Event::Input(k) => match k {
InputEvent::TextInputEvent(s) => {
hilog_info!(format!("ohos-rs macro input_text: {:?}", s).as_str());
}
_ => {
hilog_info!(format!("ohos-rs macro input:").as_str());
}
},
Event::WindowRedraw(_) => {}
_ => {
hilog_info!(format!("ohos-rs macro: {:?}", types.as_str()).as_str());
}
});
}