entity_allocatable

Attribute Macro entity_allocatable 

Source
#[entity_allocatable]
Expand description

自动为结构体/枚举实现 IEntityAllocatable 的属性宏。

参数(均为可选,顺序不限):

  • policy = ... 选择分配策略。可接受:
    • 短名称:Policy128 | Policy256 | Policy512 | Policy1024 | Policy2048 | Policy4096
    • 完整类型名(不需要带类型参数):EntityAllocPolicy256
    • 整数字面量:128 | 256 | 512 | 1024 | 2048 | 4096 默认:Policy256
  • ptrid = TypePath 使用你自定义的 PtrID 类型(必须实现 Copy + Eq,并提供 From<PtrID<Self>>From<Custom> for PtrID<Self> 转换)。
  • wrapper = Ident 生成一个透明的 PtrID 包装新类型(字段为 pubDebug 打印指针地址)。
  • opaque_wrapper = Ident 生成一个不透明的 PtrID 包装新类型(字段为私有,Debug 隐藏指针)。

冲突与重复:

  • ptrid 不能与 wrapper/opaque_wrapper 同时出现;
  • wrapperopaque_wrapper 不能同时出现;
  • 同一键名重复书写会报编译错误。

示例:

use mtb_entity_slab::entity_allocatable;

#[entity_allocatable]
struct A;

#[entity_allocatable(policy = Policy512)]
struct B<T>(T);

#[entity_allocatable(wrapper = CPtr)]
struct C;

#[entity_allocatable(opaque_wrapper = DPtr, policy = 1024)]
enum D { X, Y }

#[entity_allocatable(ptrid = my_crate::MyPtrId)]
struct E;

English brief: Attribute macro implementing IEntityAllocatable. Args (optional, order independent): policy, ptrid, wrapper, opaque_wrapper. See README for details and examples.