roblox_rs_shared_context/
shared_context.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Default)]
4pub struct SharedContext {
5 pub imports: Vec<SharedImportFunction>,
6 pub exports: Vec<SharedExportFunction>,
7}
8
9#[derive(Serialize, Deserialize, Debug)]
10pub struct SharedImportFunction {
11 pub rust_name: String,
12 pub luau_name: String,
13 pub describe_name: String,
14 pub export_name: String,
15}
16
17#[derive(Serialize, Deserialize, Debug)]
18pub struct SharedExportFunction {
19 pub rust_name: String,
20 pub luau_name: String,
21 pub export_name: String,
22 pub describe_name: String,
23}
24
25pub enum SharedFunction<'a> {
26 Import(&'a SharedImportFunction),
27 Export(&'a SharedExportFunction),
28}
29
30impl SharedContext {
31 pub fn find_function<'a>(&'a self, name: &'_ str) -> Option<SharedFunction<'a>> {
32 let import = self.imports.iter().find(|v| v.rust_name == name);
33 let export = self.exports.iter().find(|v| v.rust_name == name);
34
35 import
36 .map(SharedFunction::Import)
37 .or(export.map(SharedFunction::Export))
38 }
39}