mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/block/mod.rs')
| -rw-r--r-- | src/block/mod.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/block/mod.rs b/src/block/mod.rs index 074e431..1a32b6b 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::collections::HashMap; use std::collections::hash_map::Entry; +use crate::access::BoxAccess; use crate::data::dynamic::DynData; pub trait BlockLogic @@ -22,12 +23,12 @@ pub trait BlockLogic pub struct Block { name: Cow<'static, str>, - logic: Box<dyn BlockLogic>, + logic: BoxAccess<'static, dyn BlockLogic + Sync>, } impl Block { - pub fn new(name: Cow<'static, str>, logic: Box<dyn BlockLogic>) -> Self + pub const fn new(name: Cow<'static, str>, logic: BoxAccess<'static, dyn BlockLogic + Sync>) -> Self { Self{name, logic} } @@ -152,12 +153,7 @@ impl<'l> BlockRegistry<'l> pub fn register(&mut self, block: &'l Block) -> Result<&'l Block, &'l Block> { - let key = match block.name - { - Cow::Borrowed(r) => r, - Cow::Owned(ref s) => s, - }; - match self.blocks.entry(key) + match self.blocks.entry(&block.name) { Entry::Occupied(e) => Err(e.get()), Entry::Vacant(e) => Ok(*e.insert(block)), |