runtime.rs

 1use std::collections::HashSet;
 2
 3use mlua::{FromLua, Lua, ToLua, Value};
 4use serde::{de::DeserializeOwned, Serialize};
 5
 6pub type Handles = HashSet<String>;
 7
 8pub trait Interface
 9where
10    Self: Sized,
11{
12    fn from_runtime<T: Runtime>(runtime: &T) -> Option<Self>;
13}
14
15pub trait Runtime
16where
17    Self: Sized,
18{
19    type Module;
20
21    fn init(plugin: Self::Module) -> Option<Self>;
22    fn handles(&self) -> Handles;
23    fn val<T: DeserializeOwned>(&self, name: String) -> Option<T>;
24    fn call<T: Serialize + DeserializeOwned>(&self, name: String, arg: T) -> Option<T>;
25
26    fn as_interface<T: Interface>(&self) -> Option<T> {
27        Interface::from_runtime(self)
28    }
29}