Skip to content

Instantly share code, notes, and snippets.

@txus
Last active March 15, 2016 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txus/78ea363da278d953a0de to your computer and use it in GitHub Desktop.
Save txus/78ea363da278d953a0de to your computer and use it in GitHub Desktop.
Is there a way to have enum branches that introduce their own type parameters?
trait Hey {
fn ha(&self) -> u32;
}
enum Foo<A> {
Ret(A),
Bar<X: Hey>(Box<Fn(X) -> Foo<A>>)
}
fn test() -> Foo<u32> {
Foo::Bar(Box::new(|x| {
Foo::Bar(Box::new(|y| {
Foo::Ret(ha(y) + ha(x))
})))
}
// actual code
enum HttpClient<R, Req: FromHttpRequest> {
Return(R),
Send(Req, Box<Fn(String) -> HttpClient<R, Req>>),
Parse(String, Box<Fn(ParseResult) -> HttpClient<R, Req>>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment