Skip to content

Use ptr::write in example #88

@bluss

Description

@bluss

This example for function State::new_userdata_typed is only correct if MyStruct does not have a destructor. The correct way to move a value into an uninitialized location is std::ptr::write

The given example:

unsafe { *state.new_userdata_typed() = MyStruct::new(...); }
state.set_metatable_from_registry("MyStruct");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions