Rework of FFI, adding a value identifier, so we can keep knowledge of data even when data moves.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,12 +4,14 @@ use indexmap::IndexMap;
|
||||
|
||||
use crate::static_data::DataLibrary;
|
||||
use crate::static_data::MoveData;
|
||||
use crate::StringKey;
|
||||
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
|
||||
/// A library to store all data for moves.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub struct MoveLibrary {
|
||||
/// A unique identifier so we know what value this is.
|
||||
identifier: ValueIdentifier,
|
||||
/// The underlying map.
|
||||
map: IndexMap<StringKey, Arc<MoveData>>,
|
||||
}
|
||||
@@ -18,6 +20,7 @@ impl MoveLibrary {
|
||||
/// Instantiates a new Move Library.
|
||||
pub fn new(capacity: usize) -> MoveLibrary {
|
||||
MoveLibrary {
|
||||
identifier: Default::default(),
|
||||
map: IndexMap::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
@@ -32,9 +35,16 @@ impl DataLibrary<'_, MoveData> for MoveLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifiable for MoveLibrary {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
self.identifier
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use hashbrown::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::static_data::libraries::data_library::DataLibrary;
|
||||
use crate::static_data::libraries::move_library::MoveLibrary;
|
||||
@@ -61,7 +71,7 @@ pub mod tests {
|
||||
let m = build_move();
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add(&StringKey::new("foo".into()), m);
|
||||
w.add(&StringKey::new("foo".into()), Arc::new(m));
|
||||
// Drops borrow as mut
|
||||
|
||||
lib
|
||||
|
||||
Reference in New Issue
Block a user