I’m writing a crate that queues closures for async dispatch, with some throttling functionality. I want to provide an abstract factory that is used to construct either a thread-based queue or a futures task-based queue. The client code doesn’t care about the underlying implementation, so I thought an abstract factory would be useful, but is there any pattern for this in Rust (besides the GoF advice)?
I’m tempted to just place an associated function on the package that returns the Queue trait that both thread queue and task queue conform to instead of creating a Factory type just to achieve the same thing.
nq::new(nd::Thread) -> Queue
nq::QueueFactory.new(nq::Thread) -> Queue
Also, I’ve read in another post that I’d need to Box the returned value. Is that true, and if so, why?