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

ambee/giterated

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

Structure refactoring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨a8f41ac

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