Skip to content

Commit 074769c

Browse files
committed
use transmute to cast dyn lifetime
Required due to rust-lang/rust#136776
1 parent 877e2ac commit 074769c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/core/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,15 @@ impl Core {
182182
let mut core = self.lock();
183183
core.input = input as *const [u8];
184184
core.input_ports = input_ports as *const [InputPort];
185-
core.audio_callback = Some(std::ptr::addr_of_mut!(audio_callback) as *mut _);
185+
// SAFETY: we extend the lifetime of audio_callback to 'static, but it will only be
186+
// used during the execution of this function. The explicit transmute is needed
187+
// due to https://github.com/rust-lang/rust/pull/136776
188+
core.audio_callback = Some(std::mem::transmute::<
189+
*mut dyn FnMut(&[AudioFrame]),
190+
*mut (dyn FnMut(&[AudioFrame]) + 'static),
191+
>(
192+
std::ptr::addr_of_mut!(audio_callback) as *mut _
193+
));
186194
std::mem::drop(core);
187195

188196
run();

0 commit comments

Comments
 (0)