Fixed plugin example in README
This commit is contained in:
13
README.md
13
README.md
@@ -208,13 +208,15 @@ abi_stable = "0.11.1"
|
|||||||
|
|
||||||
```rs
|
```rs
|
||||||
use abi_stable::std_types::{RString, RVec, ROption};
|
use abi_stable::std_types::{RString, RVec, ROption};
|
||||||
use anyrun_plugin::{plugin, PluginInfo, Match, HandleResult};
|
use anyrun_plugin::*;
|
||||||
|
|
||||||
|
#[init]
|
||||||
fn init(config_dir: RString) {
|
fn init(config_dir: RString) {
|
||||||
// Your initialization code. This is run in another thread.
|
// Your initialization code. This is run in another thread.
|
||||||
// The return type is the data you want to share between functions
|
// The return type is the data you want to share between functions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[info]
|
||||||
fn info() -> PluginInfo {
|
fn info() -> PluginInfo {
|
||||||
PluginInfo {
|
PluginInfo {
|
||||||
name: "Demo".into(),
|
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 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.
|
// The `data` is a mutable reference to the shared data type later specified.
|
||||||
vec![Match {
|
vec![Match {
|
||||||
@@ -234,13 +237,11 @@ fn get_matches(input: RString, data: &mut ()) -> RVec<Match> {
|
|||||||
}].into()
|
}].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
|
// Handle the selected match and return how anyrun should proceed
|
||||||
HandleResult::Close
|
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.
|
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.
|
||||||
|
Reference in New Issue
Block a user