I have an extension trait whose methods are just shorthands for adapters/combinators:
fn foo(self) -> ... { self.map(|i| i * 2).foo().bar() }
The return type of Trait::foo() is some nested Map<Foo<Bar<Filter..., including closures, and is therefor anonymous for all practical purposes. My problem is how to return such a type from a trait method, preferably without using Box.
impl Traitin return position would be the way to go, yet this feature is not implemented for trait methods yet.- Returning a
Box<Trait>is possible, yet I don't want to allocate for every adapter shorthanded by the trait. - I can't put the anonymous type into a struct and return that, because
struct Foo<T> { inner: T }can't be implemented (I promise an impl for allT, yet only return a specificFoo<Map<Filter<Bar...). - Existential types would probably solve the above problem, yet they won't be implemented for some time.
I could also just avoid the problem and use a macro or a freestanding function; this also feels unhygienic, though.
Any more insights?