Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifetime Issues with Scope #405

Open
BenjaminSchaaf opened this issue May 11, 2024 · 3 comments
Open

Lifetime Issues with Scope #405

BenjaminSchaaf opened this issue May 11, 2024 · 3 comments
Labels
question Further information is requested

Comments

@BenjaminSchaaf
Copy link

Some trivially valid examples are currently impossible due to lifetime annotations:

// This works fine
let mut i = 0;
lua.scope(|scope| {
    scope.create_any_userdata_ref_mut(&mut i);
});

// This fails because the type must be 'static
struct Wrapper<'a>(&'a mut i32);
let mut w = Wrapper(&mut i);
lua.scope(|scope| {
    scope.create_any_userdata_ref_mut(&mut w)
});

scope.create_any_userdata_ref_mut should not require T: 'static. The only workaround I've found is to transmute the parameter.

@khvzak
Copy link
Member

khvzak commented May 12, 2024

Try Scope::create_nonstatic_userdata. It's slower alternative that does not require T: 'static.

@khvzak khvzak added the question Further information is requested label May 12, 2024
@BenjaminSchaaf
Copy link
Author

That does work, but creating a new metaclass for almost every single function call is not a tenable situation.

@khvzak
Copy link
Member

khvzak commented May 13, 2024

Unfortunately non-'static types don't implement Any trait which is the main blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants