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

ambee/giterated

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

More restructuring

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨10b7b7c

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