Skip to content

Lifetime Issues in UserData #495

Answered by khvzak
mrxsisyphus asked this question in Q&A
Discussion options

You must be logged in to vote

You try to return an object that has reference to another object, which is not 'static, but Lua objects must be static since it does not have lifetimes.

Instead, you need to use self-referential data structures to make the object refer to itself and be 'static to meet the requirements. I would recommend ouroboros for that.
If you define HtmlElement as

#[self_referencing]
pub struct HtmlElement {
    root: Rc<Html>,
    #[borrows(root)]
    element: ElementRef<'this>
}

then you can return HtmlElement that can refer to inner (cheaply cloneable) root .

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mrxsisyphus
Comment options

Answer selected by mrxsisyphus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants