JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Before

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨e432306

⁨plugins/example-plugin/src/lib.rs⁩ - ⁨1290⁩ bytes
Raw
1 use anyhow::Error;
2 use giterated_models::{error::OperationError, object::{ObjectRequest, ObjectRequestError, ObjectResponse}, user::{DisplayName, User}};
3 use giterated_plugin::{new_stack::State, plugin};
4
5 plugin!(
6 name: "Example Plugin",
7 version: "0.0.1",
8 author: "Amber Kowalski",
9 // Experimental syntax for requesting specific plugin features
10 features: ["tracing", "tokio"],
11 description: "An example plugin to demonstrate the development process of Giterated plugins."
12 );
13
14 /// Some kind of global state for the plugin
15 struct PluginState;
16
17 /// The plugin's initialization function. Ran when the plugin is loaded, used to
18 /// build the plugin's stack.
19 #[plugin::init]
20 pub fn init(builder: &mut PluginStackBuilder) -> Result<(), Error> {
21 builder.insert_state(State);
22
23 builder
24 .object::<Instance>()
25 .object::<User>();
26
27 builder.value(value_getter);
28 builder.setting_getter(setting_getter);
29
30 Ok(())
31 }
32
33 async fn handler(
34 object: User,
35 operation: ObjectRequest,
36 state_extractor: State<PluginState>
37 ) -> Result<ObjectResponse, OperationError<ObjectRequestError>> {
38 todo!()
39 }
40
41 async fn setting_getter(
42 object: User,
43 state_extractor: State<PluginState>
44 ) -> Result<DisplayName, OperationError<Error>> {
45 todo!()
46 }