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

This commit is contained in:
2022-10-08 13:15:04 +02:00
parent 84ddf0307d
commit 41b40ef98e
38 changed files with 582 additions and 230 deletions

View File

@@ -2,9 +2,12 @@
pub use random::Random;
#[doc(inline)]
pub use string_key::StringKey;
#[doc(inline)]
pub use value_identifier::*;
/// The random module defines a RNG implementation used in pkmn_lib
mod random;
/// The string_key module defines a custom string handling for reduced allocations and fast lookups
/// and equality checks.
mod string_key;
mod value_identifier;

View File

@@ -0,0 +1,22 @@
use std::sync::atomic::{AtomicUsize, Ordering};
static CURRENT: AtomicUsize = AtomicUsize::new(1);
/// An extremely basic way to identify a piece of data.
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
#[repr(C)]
pub struct ValueIdentifier(usize);
impl Default for ValueIdentifier {
fn default() -> Self {
Self {
0: CURRENT.fetch_add(1, Ordering::SeqCst),
}
}
}
/// An object with a specific identifier.
pub trait ValueIdentifiable {
/// Get the identifier for the current object.
fn value_identifier(&self) -> ValueIdentifier;
}