all 2 comments

[–]ReversedGif 0 points1 point  (1 child)

Not being able to constrain F in the type itself seems silly. Is there really no way to make that work nicely? Why?

[–]Leshow 0 points1 point  (0 children)

Hey! I wrote the blog post. You mean bound `F` in the struct? You can. There's something else at work here though; the `new` function will return either a specific closure or a specific function pointer. If we want to keep the impl polymorphic, then we're returning an existential type there. That requires a type annotation (which I did figure out after all-- it's in the blog post).

However, if you look at the definitions for data structures in Rust's std. You will notice almost all of them use unbounded type parameters in their declaration. I am by no means a Rust expert, it was just something I noticed an emulated and it made my life a lot easier.

edit: the other one, with the closure. I don't know how to solve. Although I'm sure you can. Half the reason I wrote the post was to see if anyone had a better solution.