Skip to content

rebind! macro #2

@CeleritasCelery

Description

@CeleritasCelery

The rebind macro has this definition:

rune/src/arena/mod.rs

Lines 96 to 102 in 7136b74

macro_rules! rebind {
($item:ident, $arena:ident) => {
#[allow(unused_qualifications)]
let bits: $crate::object::RawObj = $item.into();
let $item = unsafe { $arena.rebind_raw_ptr(bits) };
};
}

We are casting the object into a raw form that removes the lifetime. Then we call an unsafe function to create a new object from that raw pointer

Why this is safe

We are not actually changing the &mut reference to Arena. Instead we are releasing it then reborrowing it immutabley. We make sure to shadow the name so the old binding is no longer available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    unsound?Unsure if this unsafe code is sound

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions