Fixed plugin example in README

This commit is contained in:
Kirottu
2023-05-01 11:19:12 +03:00
parent 8e5bff9e91
commit 90ecba8261

View File

@@ -208,13 +208,15 @@ abi_stable = "0.11.1"
```rs
use abi_stable::std_types::{RString, RVec, ROption};
use anyrun_plugin::{plugin, PluginInfo, Match, HandleResult};
use anyrun_plugin::*;
#[init]
fn init(config_dir: RString) {
// Your initialization code. This is run in another thread.
// The return type is the data you want to share between functions
}
#[info]
fn info() -> PluginInfo {
PluginInfo {
name: "Demo".into(),
@@ -222,7 +224,8 @@ fn info() -> PluginInfo {
}
}
fn get_matches(input: RString, data: &mut ()) -> RVec<Match> {
#[get_matches]
fn get_matches(input: RString) -> RVec<Match> {
// The logic to get matches from the input text in the `input` argument.
// The `data` is a mutable reference to the shared data type later specified.
vec![Match {
@@ -234,13 +237,11 @@ fn get_matches(input: RString, data: &mut ()) -> RVec<Match> {
}].into()
}
fn handler(selection: Match, input: RString, data: &mut ()) -> HandleResult {
#[handler]
fn handler(selection: Match) -> HandleResult {
// Handle the selected match and return how anyrun should proceed
HandleResult::Close
}
// The type of the data we want to store is the last one, we don't need it in this one so it can be the unit type.
plugin!(init, info, get_matches, handler, ());
```
And that's it! That's all of the API needed to make runners. Refer to the plugins in the [plugins](plugins) folder for more examples.