Expand description
§jasper-plugin-sdk
Jasper 后端插件(wasm,spec 0.3)的 Rust SDK:封装 ABI(spec §6),
作者只写业务函数/类型,用 register! 一行接入。
ⓘ
use jasper_plugin_sdk as sdk;
use sdk::core::model::Note;
fn before_save(mut note: Note) -> Result<Note, String> {
note.body = note.body.lines().map(|l| l.trim_end()).collect::<Vec<_>>().join("\n");
Ok(note)
}
sdk::register! { before_save: before_save }
// 或:sdk::register! { storage: MyStorage }(impl sdk::storage::Storage)
// 或组合任意子集:sdk::register! { before_save: before_save, command: run, ui: render }插件 crate 须为 crate-type = ["cdylib"],目标 wasm32-unknown-unknown。
Re-exports§
pub use rt::PluginError;pub use jasper_core as core;pub use serde_json;
Modules§
- host
- 宿主能力的类型化封装(spec §6.5「插件 → host」方法)。 每个函数对应一个 host_call 方法;所需能力见 spec §7,未授权时返回 code=“forbidden”。
- rt
- ABI 运行时(spec §6):内存分配、u64 打包、JSON 信封。
- storage
- 存储 provider(spec §3.9 / §6.5
storage.*,0.2 新增)。
Macros§
- register
- 生成
plugin_alloc/plugin_free/plugin_dispatch三个 ABI 导出(spec §6.1/§6.2)。 可挂载(任意顺序、可组合):