this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Starting over with how I structure the data of this module to be more Rust-like

+1 -56
+1 -42
src/lib.rs
··· 11 11 pub mod dnd5e; 12 12 13 13 #[cfg(feature = "sf2e")] 14 - pub mod sf2e; 15 - 16 - use hooks::Hooks; 17 - use traits::DiceWireSystem; 18 - use uuid::Uuid; 19 - use std::{collections::HashMap, str::FromStr, sync::{Mutex, OnceLock}}; 20 - use wasm_bindgen::prelude::*; 21 - 22 - static RUNTIME: OnceLock<Mutex<Runtime>> = OnceLock::new(); 23 - 24 - fn get_runtime() -> &'static Mutex<Runtime> { 25 - RUNTIME.get_or_init(|| Mutex::new(Runtime::new())) 26 - } 27 - 28 - pub struct Runtime { 29 - pub systems: HashMap<String, Box<dyn DiceWireSystem>>, 30 - hooks: Hooks 31 - } 32 - 33 - impl Runtime { 34 - fn new() -> Self { 35 - Self { 36 - systems: HashMap::new(), 37 - hooks: Hooks::new() 38 - } 39 - } 40 - } 41 - 42 - #[wasm_bindgen] 43 - pub fn get_system_actor(sys_id: String, actor_id: String) -> Vec<u8> { 44 - let runtime = get_runtime() 45 - .lock() 46 - .unwrap(); 47 - 48 - let system_data = runtime 49 - .systems 50 - .get(&sys_id) 51 - .unwrap(); 52 - 53 - let actor_data = system_data.get_actor(Uuid::from_str(&actor_id).unwrap()); 54 - actor_data.serialize() 55 - } 14 + pub mod sf2e;
-14
src/traits.rs
··· 1 - use uuid::Uuid; 2 - 3 - pub trait Serializable: Send + Sync { 4 - fn serialize(&self) -> Vec<u8>; 5 - } 6 - 7 - pub trait DiceWireSystem: Send + Sync { 8 - fn name(&self) -> &str; 9 - fn get_actor(&self, uuid: Uuid) -> Box<dyn DiceWireActor>; 10 - } 11 - 12 - pub trait DiceWireActor: Send + Sync + Serializable { 13 - 14 - }