use core::ffi::c_void;
use polyplug_utils::HostContractId;
use crate::{
dispatch::{dispatch_mechanisms::DispatchMechanisms, dispatch_type::DispatchType},
host::HostContractInstance,
types::Version,
};
#[repr(C)]
pub struct HostContractInterface {
pub contract_id: HostContractId,
pub contract_version: Version,
pub singleton: bool,
pub dispatch_type: DispatchType,
pub runtime: *mut c_void,
pub user_data: *mut c_void,
pub create_instance: unsafe extern "C" fn(
this: *const HostContractInterface,
args: *const (),
out_instance: *mut HostContractInstance,
),
pub destroy_instance:
unsafe extern "C" fn(this: *const HostContractInterface, instance: HostContractInstance),
pub dispatch: DispatchMechanisms,
}
unsafe impl Send for HostContractInterface {}
unsafe impl Sync for HostContractInterface {}
#[cfg(test)]
mod tests {
use super::HostContractInterface;
use core::mem::{align_of, offset_of, size_of};
#[test]
fn layout_host_contract_interface() {
assert_eq!(size_of::<HostContractInterface>(), 80);
assert_eq!(align_of::<HostContractInterface>(), 8);
assert_eq!(offset_of!(HostContractInterface, contract_id), 0);
assert_eq!(offset_of!(HostContractInterface, contract_version), 8);
assert_eq!(offset_of!(HostContractInterface, singleton), 20);
assert_eq!(offset_of!(HostContractInterface, dispatch_type), 24);
assert_eq!(offset_of!(HostContractInterface, runtime), 32);
assert_eq!(offset_of!(HostContractInterface, user_data), 40);
assert_eq!(offset_of!(HostContractInterface, create_instance), 48);
assert_eq!(offset_of!(HostContractInterface, destroy_instance), 56);
assert_eq!(offset_of!(HostContractInterface, dispatch), 64);
}
}