polyplug_abi 0.1.1

ABI type definitions for the polyplug plugin runtime
use crate::dispatch::{native_dispatch::NativeDispatch, vm_dispatch::VmDispatch};

/// Union of dispatch mechanisms — use based on `dispatch_type`.
///
/// # Safety
/// Access the correct variant based on `GuestContractInterface::dispatch_type`:
/// - `dispatch_type == Native` → access `.native`
/// - `dispatch_type == VirtualMachine` → access `.vm`
#[repr(C)]
pub union DispatchMechanisms {
    /// Native dispatch data (when dispatch_type == Native).
    pub native: NativeDispatch,
    /// VM dispatch data (when dispatch_type == VirtualMachine).
    pub vm: VmDispatch,
}

impl Clone for DispatchMechanisms {
    fn clone(&self) -> Self {
        *self
    }
}

impl Copy for DispatchMechanisms {}

#[cfg(test)]
mod tests {
    use core::mem::{align_of, size_of};

    use crate::dispatch::dispatch_mechanisms::DispatchMechanisms;

    #[test]
    fn layout_plugin_dispatch() {
        assert_eq!(size_of::<DispatchMechanisms>(), 16);
        assert_eq!(align_of::<DispatchMechanisms>(), 8);
    }
}