| Crates.io | covey-plugin |
| lib.rs | covey-plugin |
| version | 0.0.2 |
| created_at | 2025-03-08 09:44:00.778797+00 |
| updated_at | 2025-03-08 10:13:43.747892+00 |
| description | APIs for creating Covey plugins |
| homepage | |
| repository | https://github.com/blorbb/covey |
| max_upload_size | |
| id | 1584261 |
| size | 84,448 |
Rust bindings for a covey plugin.
See a bunch of examples in covey-plugins. Protobuf definitions are in proto/plugin.proto, if you want to make bindings for another language.
Example implementation below. For more details, see this crate's documentation.
Add covey-plugin as a dependency to Cargo.toml.
use covey_plugin::{clone_async, Action, Input, List, ListItem, Plugin, Result};
// store any configuration / cache here.
// if none are needed, a unit struct `struct Open;` will work.
struct Open {
urls: Vec<(String, urls::UrlsValue)>,
}
impl Plugin for Open {
// `Config` is a struct generated by `include_manifest!()` below.
type Config = Config;
async fn new(config: Self::Config) -> Result<Self> {
Ok(Self {
urls: config.urls.into_iter().collect(),
})
}
async fn query(&self, query: String) -> Result<List> {
// do some logic here...
Ok(List::new(vec![
ListItem::new("list item title")
.with_description("a description")
// define callbacks that will be triggered when
// the user activates a command.
// this method is defined an extension trait
// generated by `include_manifest!()`.
.on_activate(move || async move {
Ok([Action::Close, Action::Copy("wahoo")])
})
// you will often need to clone values into
// the callback. use the helper macro to make
// this easier.
.on_complete(clone_async!(query, || {
Ok(Input::new(query))
}))
]))
}
}
// generates types from reading `../manifest.toml`.
// also defines an extension trait for methods like `.on_activate`.
covey_plugin::include_manifest!();
fn main() {
// this will run the server.
// it requires the name of the binary to be passed in.
// use `env!` to get it from the cargo project.
covey_plugin::run_server::<Open>(env!("CARGO_BIN_NAME"))
}
Currently, only Rust bindings exist. Bindings for other languages may be made in the future.
The program needs to run a server with RPC services that follow the protobuf definition.
[::1]) and print the port to stdout (e.g. 12345).
http://[::1]:<port>.