orottier/web-audio-api-rs

Ensure that AudioNode trait is 'object safe'

Closed this issue · 0 comments

I just checked, the AudioNode trait is object safe, so users can construct e.g. a Vec<Box<dyn AudioNode>>
The AudioScheduledSourceNode is not, because of the recently added onended method that takes a generic param. I think that is acceptable. The generic param make the method a bit more user friendly, otherwise we need to ask users to box the provided closure.

#[allow(dead_code)]
fn ensure_audio_node_object_safe() {
    let context = AudioContext::default();
    let node = context.create_constant_source();
    let _object: Box<dyn AudioNode> = Box::new(node); // SUCCEEDS
}

#[allow(dead_code)]
fn ensure_audio_scheduled_source_node_object_safe() {
    let context = AudioContext::default();
    let node = context.create_constant_source();
    let _object: Box<dyn AudioScheduledSourceNode> = Box::new(node); // FAILS
}

I will add the first test to the test suite