Complete refactor of the FFI to use handles instead of pointers.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-06-24 14:44:23 +02:00
parent 4c222cb753
commit 78bb91093b
76 changed files with 1510 additions and 1952 deletions

View File

@@ -5,16 +5,14 @@ use indexmap::IndexMap;
use crate::static_data::Ability;
use crate::static_data::DataLibrary;
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
use crate::StringKey;
/// A storage for all abilities that can be used in this data library.
pub trait AbilityLibrary: DataLibrary<dyn Ability> + ValueIdentifiable + Debug {}
pub trait AbilityLibrary: DataLibrary<dyn Ability> + Debug {}
/// A storage for all abilities that can be used in this data library.
#[derive(Debug)]
pub struct AbilityLibraryImpl {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The underlying map for the library.
map: IndexMap<StringKey, Arc<dyn Ability>>,
}
@@ -23,7 +21,6 @@ impl AbilityLibraryImpl {
/// Instantiates a new ability library.
pub fn new(capacity: usize) -> Self {
Self {
identifier: Default::default(),
map: IndexMap::with_capacity(capacity),
}
}
@@ -40,12 +37,6 @@ impl DataLibrary<dyn Ability> for AbilityLibraryImpl {
}
}
impl ValueIdentifiable for AbilityLibraryImpl {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}
}
#[cfg(test)]
#[allow(clippy::indexing_slicing)]
#[allow(clippy::unwrap_used)]
@@ -57,7 +48,7 @@ pub mod tests {
use std::sync::Arc;
pub fn build() -> AbilityLibraryImpl {
let mut lib = AbilityLibraryImpl::new(1);
let lib = AbilityLibraryImpl::new(1);
lib.add(
&StringKey::new("test_ability"),
Arc::new(AbilityImpl::new(