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

ambee/giterated

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

MOre pre vtable changes

Amber - ⁨1⁩ year ago

parent: tbd commit: ⁨9cfa135

⁨plugins/example-plugin/src/main.rs⁩ - ⁨1514⁩ bytes
Raw
1 use giterated_models::object_backend::ObjectBackend;
2 use giterated_models::{
3 instance::Instance,
4 object::ObjectRequest,
5 operation::OperationState,
6 user::{DisplayName, User},
7 };
8 use giterated_plugin::{callback::RuntimeState, handle::PluginHandle, new_stack::Runtime};
9 use tracing::{info, Level};
10
11 #[tokio::main]
12 async fn main() -> Result<(), anyhow::Error> {
13 tracing_subscriber::fmt()
14 .pretty()
15 .with_thread_names(true)
16 .with_max_level(Level::TRACE)
17 .init();
18
19 let handle = PluginHandle::from_dylib("example_plugin_dylib.dll").unwrap();
20
21 info!("1");
22
23 let mut runtime = Runtime::new();
24
25 info!("2");
26
27 runtime.insert_plugin(handle);
28
29 info!("3");
30
31 runtime.init();
32
33 info!("4");
34
35 let runtime = unsafe { RuntimeState::from_static() };
36
37 let _object_request = ObjectRequest(String::from("foobar"));
38
39 let _state = OperationState::default();
40
41 let _instance = runtime
42 .get_object::<Instance>("giterated.dev", &OperationState::default())
43 .await?;
44
45 let mut user = runtime
46 .get_object::<User>("ambee:giterated.dev", &OperationState::default())
47 .await?;
48
49 let display_name = user.get::<DisplayName>(&OperationState::default()).await?;
50
51 info!("Display name for user as a value: {}", display_name);
52
53 let display_name = user
54 .get_setting::<DisplayName>(&OperationState::default())
55 .await?;
56
57 info!("Display name for user as a setting: {}", display_name);
58
59 Ok(())
60 }
61