-
Notifications
You must be signed in to change notification settings - Fork 89
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
Stream callback defined as 'static #151
Comments
I believe it is necessary for the compiler in order to allow the callback to be We may be able to improve this by assuming that a I'm afraid I don't have the time to look into this further myself. In the meantime, you should be able to get around this by wrapping your Sorry I don't have time to dig further, I hope this helps at least! |
@mitchmindtree thank you very much for your elaborated response, it has been very helpful. It makes sense to me that the callback lifetime is limited by the lifetime of the You were right, and by using Arc<Mutex<Handler>> I was able to call the mutable |
Not sure if you're still having troubles since this issue was opened a while ago, but I recently got this working with Trait types; see this repo at cc5c7e11dd. Of course the example is kind of weird since I'm effectively creating silence by adding a sine with its negative, but you get the idea. I'm also messing around with a producer/consumer model and passing a |
There is a simple trick that will give an audio stream a non-static lifetime, which I got from @Timmmm. |
Note that I have temporarily abandoned soundio-rs because I couldn't figure out all the borrowing and lifetime stuff. The |
I was wondering if there is an important reason for the callback to be defined as
'static
at:https://github.com/RustAudio/rust-portaudio/blob/master/src/stream.rs#L1294
This implies that I can not wrap the logic for audio handling in an
struct
and useself
within the callback (even ifSend
is implemented for it). It is not possible neither to pass any kind of reference to an struct that doesn't have static lifetime, which forces to create the audio handling struct just near the callback definition inside the same function.For example, the following code is wrong:
And fails with:
The previous code only compiles when the
Handler
is instantiated insiderun
.The text was updated successfully, but these errors were encountered: