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

EventContext Lifetime Makes It Impossible to Store #21

Open
anlumo opened this issue Apr 21, 2021 · 0 comments
Open

EventContext Lifetime Makes It Impossible to Store #21

anlumo opened this issue Apr 21, 2021 · 0 comments

Comments

@anlumo
Copy link

anlumo commented Apr 21, 2021

Hi,

mpv::create_event_context returns an EventContext<'a> with the lifetime of the Mpv instance. While this works fine as long as this event context is only used in the function it is created in (such as in your examples), this makes it impossible to store the event context in a struct that also contains the Mpv instance (since you can't have a lifetime referencing something within the same struct in Rust). You also can't create a new EventContext<'a> every time you need it, since there's this atomic boolean to make sure that only once instance is ever created.

What is the reason why EventContext isn't simply held in the Mpv instance and only ever returned by reference in a getter? This way its lifetime also can never exceed the Mpv instance's lifetime, and you don't even have to do the whole atomic boolean dance.

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

No branches or pull requests

1 participant