#[resource_impl]Expand description
Helper attribute for Resource implementations
When an impl Resource for Type block is annotated with this attribute, it will automatically
set the IMPLEMENTS_... associated constants for all implemented callback methods. Thus,
instead of
ⓘ
struct ResourceType {}
impl Resource for ResourceType
{
const IMPLEMENTS_DESTRUCTOR: bool = true;
fn destructor(...) { ... }
}it is enough to provide the implementation:
ⓘ
#[rustler::resource_impl]
impl Resource for ResourceType
{
fn destructor(...) { ... }
}The resource type is also automatically registered by default, it does not have to be manually
registered in a load callback. The automatic registration can be disabled with the register
parameter:
ⓘ
#[rustler::resource_impl]
impl Resource for ResourceType
{
...
}
// no load callback necessaryIf registration is disabled, the resource type has to be registered manually. It is not
possible to use the old resource! macro for this, as that injects another impl Resource
block.
ⓘ
#[rustler::resource_impl(register = false)]
impl Resource for ResourceType
{
...
}
pub fn on_load(env: Env) -> bool {
env.register::<ResourceType>().is_ok()
}