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

ambee/giterated

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

Fucking whatever there you go

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨57c2ca5

⁨plugins/example-plugin/src/main.rs⁩ - ⁨1844⁩ bytes
Raw
1 use giterated_models::{
2 instance::Instance,
3 object::{GiteratedObject, ObjectRequest},
4 operation::GiteratedOperation,
5 settings::{GetSetting, Setting},
6 user::{DisplayName, User},
7 value::GetValue,
8 };
9 use giterated_plugin::{handle::PluginHandle, new_stack::Runtime, GiteratedPluginApi};
10 use tracing::{info, Level};
11
12 fn main() {
13 tracing_subscriber::fmt()
14 .pretty()
15 .with_thread_names(true)
16 .with_max_level(Level::TRACE)
17 .init();
18
19 let mut handle = PluginHandle::from_dylib("example_plugin_dylib.dll").unwrap();
20
21 let mut runtime = Runtime::<()>::new();
22
23 runtime.insert_plugin(handle);
24
25 let object_request = ObjectRequest(String::from("foobar"));
26
27 match runtime.handle(
28 Instance::object_name(),
29 ObjectRequest::operation_name(),
30 "meow",
31 &serde_json::to_vec(&object_request).unwrap(),
32 ) {
33 Ok(success) => info!("handler call success!"),
34 Err(_) => info!("handler call error"),
35 }
36
37 match runtime.handle(
38 User::object_name(),
39 <GetValue as GiteratedOperation<User>>::operation_name(),
40 "amber:giterated.dev",
41 &serde_json::to_vec(&GetValue {
42 value_name: String::from("display_name"),
43 })
44 .unwrap(),
45 ) {
46 Ok(success) => info!("get_value handler call success!"),
47 Err(_) => info!("get_value handler call error"),
48 }
49
50 match runtime.handle(
51 User::object_name(),
52 <GetSetting as GiteratedOperation<User>>::operation_name(),
53 "amber:giterated.dev",
54 &serde_json::to_vec(&GetSetting {
55 setting_name: DisplayName::name().to_string(),
56 })
57 .unwrap(),
58 ) {
59 Ok(success) => info!("get_setting handler call success!"),
60 Err(_) => info!("get_setting handler call error"),
61 }
62 }
63