1pub type TypeName = &'static str;
2
3#[derive(Clone)]
4pub struct Parameter {
5 pub name: String,
6 pub ty: TypeName,
7}
8
9#[derive(Clone)]
10pub struct Method
11{
12 pub method_pointer: *mut fn(),
14 pub lang_marshalls: Vec<(&'static str, *mut fn())>,
18
19 pub name: &'static str,
21 pub parameters: Vec<Parameter>,
23 pub ret: Option<TypeName>,
25
26 pub is_static: bool,
28}
29
30#[derive(Clone)]
31pub struct Field
32{
33 pub field_offset: usize,
35
36 pub ty: TypeName,
37 pub name: &'static str,
38}
39
40#[derive(Clone)]
41pub struct Class
42{
43 pub name: String,
44 pub fields: Vec<Field>,
45 pub methods: Vec<Method>,
46}
47
48pub trait PluggableFields
49{
50 fn pluggable_fields(&self) -> Vec<Field>;
51}
52
53pub trait PluggableMethods
54{
55 fn pluggable_methods(&self) -> Vec<Method>;
56}
57
58pub trait Marshall
60{
61 type Value;
62
63 fn to_bool(value: Self::Value) -> bool;
64
65 fn to_u8(value: Self::Value) -> u8;
66 fn to_u16(value: Self::Value) -> u16;
67 fn to_u32(value: Self::Value) -> u32;
68 fn to_u64(value: Self::Value) -> u64;
69 fn to_i8(value: Self::Value) -> i8;
70 fn to_i16(value: Self::Value) -> i16;
71 fn to_i32(value: Self::Value) -> i32;
72 fn to_i64(value: Self::Value) -> i64;
73
74 fn to_f32(value: Self::Value) -> f32;
75 fn to_f64(value: Self::Value) -> f64;
76
77 fn to_string(value: Self::Value) -> String;
78}
79
80pub trait Pluggable : PluggableFields + PluggableMethods
100{
101 fn name(&self) -> &'static str;
102
103 fn fields(&self) -> Vec<Field> { PluggableFields::pluggable_fields(self) }
104 fn methods(&self) -> Vec<Method> { PluggableMethods::pluggable_methods(self) }
105
106 fn class(&self) -> Class {
107 Class {
108 name: self.name().to_owned(),
109 fields: self.fields(),
110 methods: self.methods(),
111 }
112 }
113}
114
115impl Method {
116 pub fn marshall(&self, lang_name: &str) -> *mut fn() {
118 self.lang_marshalls.iter().find(|m| m.0 == lang_name).unwrap().1
119 }
120}
121