These are chat archives for rust-lang/rust

30th
May 2016
Jacob Payne
@Latrasis
May 30 2016 05:29

Can anybody tell me if it's possible to define a generic for tuples?

fn foo<T:(A)>(param: T) {}; // Takes a tuple of length 1
fn foo<T:(A, B)>(param: T) {}; // Takes a tuple of length 2
fn foo<T:(A,B,C)>(param: T) {}; // Takes a tuple of length 2

Since a tuple is a primitive type I would think you could set it within a generic, however i get a syntax error.

Peter Atashian
@retep998
May 30 2016 05:53
@Latrasis You'd have to do fn foo<A, B, C>(param: (A, B, C))
Jacob Payne
@Latrasis
May 30 2016 05:54
@retep998 : So i can't have both?
Peter Atashian
@retep998
May 30 2016 05:54
You can't use a tuple as a bound on a generic
Jacob Payne
@Latrasis
May 30 2016 05:59
Aww...
panicbit
@panicbit
May 30 2016 10:16
@Latrasis You could use a trait that you impl some tuples for