Cannot satisfy `_: Runnable<dyn A, Arc<Mutex<Option<Box<dyn A>>>>>`

I'm afraid it's basically the same situation. Imagine a function like this:

fn choose_wisely(rr: Arc<dyn LockableOption<dyn Decoder<u8>>>) {
    // I only have the information in the signature above
    // I want to do:
    <FfmpegDecoder<u8> as DecoderRunnable::<u8>>::run(rr);
    // But instead of `FfmpegDecoder<_>` I want to use whatever is is
    // that `dyn Decoder<_>` can downcast to
    //
    // But I also don't want to lock, unwrap, etc. in this function.
    // :-(
}

But! I did think of something. This works if you can work it into your model somehow. You have to create the ArcHolder at some point when you still know the type underneath the dyn Decoder.

(The only significant changes to your playground are in main and the things that follow main.)

That's not actually true, you can finagle it into dyn Decoder. Though I wouldn't if you don't need to.

pub trait Decoder<T>: Send + RunPtrProducer<T> {}

pub trait RunPtrProducer<T> {
    fn run_ptr(&self) -> fn(Arc<dyn LockableOption<dyn Decoder<T>>>);
}

impl<T, U: DecoderRunnable<T>> RunPtrProducer<T> for U {
    fn run_ptr(&self) -> fn(Arc<dyn LockableOption<dyn Decoder<T>>>) {
        <U as DecoderRunnable<T>>::run
    }
}

Sloppily adjusted playground.

Edit: I just had a thought that this is might be the DynTrait pattern I've seen in this forum a few times, but more duct tape and bubblegummy. Rust doesn't like you putting run_ptr directly in Decoder with a default implementation that refers to DecoderRunnable ("being phased out, will become a hard error"). And you can't make DecoderRunnable a supertrait of Decoder due to object safety. This is just working around the latter.

But I'm not going to pursue that thought any further for now.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.