Thu Mar 14 12:27:57 EDT 2019

specyfing return value traits

This is impl Trait:


For reference: look at how the JackClient trait is handled in the
looper project.  Two things are important:

- client.activate_async from the jack library returns a type that is
  parameterized by a closure, so we can't even specify it explicitly.
- the solution i've found is to put it in a struct that is
  parameterized by this type.

struct SimpleJackClient<P> {
    async_client: jack::AsyncClient<(), P>

- then create a trait that is implemented with P constrained:

impl<P> JackClient for SimpleJackClient<P>
    where P:jack::ProcessHandler

- this trait can be reused for other things, but for now the only
  important property is that it is implemented for the
  SimpleJackClient for any return value of client.activate_sync

- my main constructor returns "impl JackClient".  this means it can
  still be inlined into another struct.  i.e. I'm not yet limiting
  that possibility yet.

- however, it ends up being stored in some object store as a
  Box<JackClient> which is a trait object.

Conclusion: I did some extra wrapping because I need it anyway, but
there are 3 things to distinguis:

- impl Trait will be a concrete type known at compile time
- Box<Trait> is such a concrete type inside a box, exposing only the interface
- &Trat is similar, but just an abstract reference to a concrete type