-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Cannot borrow a variable in the jack process callback #60
Comments
Taking On a similar note, I was planning on having a handler that implements the ProcessHandler trait by taking closures. IE: let my_handler = ClosureHandler::new()
.with_process(|....|....)
.with_port_rename(|...|....); |
Thanks. |
You can try out this branch https://github.com/wmedrano/rust-jack/tree/mut-handlers You can either implement the |
Thanks for the very quick response. I hope to find some time next week-end to try it out. I had a quick look at the definition of the |
The pull request solved it for me. Thanks. |
I want to use a variable that I borrow from elsewhere in the process callback.
First method is to use the closure approach (example is a slightly modification of the playback_capture example):
When I try this, I get the following example:
Second method is to use a struct that implements the JackHandler trait and that borrows the variable (again a slightly modified version of the playback_capture example):
Here, I get the following error:
I could get around this second error by using interior mutability with a
Mutex
(RefCell
doesn't work because it doesn't implementSync
), but the documentation of rust-jack especially discourages calling functions likepthread_mutex_lock
in theprocess
function, so this doesn't seem to be a good idea. For implementing theJackHandler
trait for certain closures, an unsafe mutable transmute is used (rust-jack/src/client/callbacks.rs
, line 149), so that's still an option.Am I missing something else? Is it a good idea to have the
process
function in theJackHandler
take an&mut self
parameter instead of&self
?The text was updated successfully, but these errors were encountered: