Studying this piece of code from audio-visualizer, I extracted it in my play project as
pub fn setup_stream(config: &StreamConfig, device: &Device, buffer: Arc<Mutex<AllocRingBuffer<f32>>>) -> Stream {
device
.build_input_stream(
config,
move |data: &[f32], _info| {
let mut audio_buffer = buffer.lock().unwrap();
audio_buffer.extend(data.iter().copied());
},
move |error: StreamError| eprintln!("error on input audio stream: {}", error),
None
)
.unwrap()
}
Build is successful with ringbuffer v0.13 but it fails with v0.14:
error[E0277]: `*mut f32` cannot be sent between threads safely
--> src/lib.rs:24:13
|
22 | .build_input_stream(
| ------------------ required by a bound introduced by this call
23 | config,
24 | / move |data: &[f32], _info| {
25 | | let mut audio_buffer = buffer.lock().unwrap();
26 | | audio_buffer.extend(data.iter().copied());
27 | | },
| |_____________^ `*mut f32` cannot be sent between threads safely
|
= help: within `AllocRingBuffer<f32>`, the trait `Send` is not implemented for `*mut f32`
= note: required because it appears within the type `AllocRingBuffer<f32>`
= note: required for `Mutex<AllocRingBuffer<f32>>` to implement `Sync`
= note: required for `Arc<Mutex<AllocRingBuffer<f32>>>` to implement `Send`
note: required because it's used within this closure
--> src/lib.rs:24:13
|
24 | move |data: &[f32], _info| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `build_input_stream`
--> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cpal-0.15.2/src/traits.rs:134:46
|
134 | D: FnMut(&[T], &InputCallbackInfo) + Send + 'static,
| ^^^^ required by this bound in `DeviceTrait::build_input_stream`
There is no changelog or github tag to compare, but looking at the doc.rs pages for 0.13 and 0.14 what stands out is that it went from Send to !Send. Was that expected?
Studying this piece of code from
audio-visualizer, I extracted it in my play project asBuild is successful with ringbuffer
v0.13but it fails withv0.14:There is no changelog or github tag to compare, but looking at the doc.rs pages for 0.13 and 0.14 what stands out is that it went from
Sendto!Send. Was that expected?