HRTB lifetime issue

Yeah, I won't have time to really dig into this right now, but a few passing remarks:

trait Resource<'a, T> where Box<Self>: Sized {
    fn get(&'a self) -> T;
}
  • Box<_> is always Sized
  • You never seem to need a specific 'a, but every 'a, so why not use:
    trait Resource<T> {
       fn get(&self) -> &T;
    }
    

That would make these:

impl<R, R2> Builder<R2> for ListenerBuilder<R>
where
    R: AsyncRead + Unpin + Send + 'static,
    R2: for<'a> Resource<'a, &'a HashMap<Source, Arc<Mutex<R>>>> +
        for<'a> Resource<'a, &'a HashMap<Source, Sender<String>>>

Look like this:

impl<R, R2> Builder<R2> for ListenerBuilder<R>
where
    R: AsyncRead + Unpin + Send + 'static,
    R2: Resource<HashMap<Source, Arc<Mutex<R>>>> +
        Resource<HashMap<Source, Sender<String>>>

Which is what these look like already (which don't compile with trait as you presented it due to the missing lifetime parameter):

trait SuperResource<R1, R2, W1, W2>:
    Resource<HashMap<Source, Arc<Mutex<R1>>> + 
    Resource<HashMap<Source, Sender<String>>> +
    // ...

...but maybe this is another "borrowed-or-owned" situation and the directly above code was stale?


Scratchpad for myself. Looking at all the borrowing calls in the erroring portion, that may be where the lifetime stuff comes in.


Yeah, could be painful. Here's what I usually link to on the topic of abstracting over owned-or-borrowed, though your use case may be different. (Not entirely sure it applies, just leaving that here in case you or someone else wants to persue it while I'm AFK).