But this look suspiciously like an Fn* trait, in that case, using nightly you could use overloadable as follows:
#![feature(unboxed_closures, fn_traits)]
use overloadable::overloadable;
overloadable! {
pub test as
fn(x: ()) {
},
// Note that `(T,)` is a one-tuple because of the leading comma
fn<T>(x: (T,)) {
println!("one arg");
},
fn<T, U>(x: (T, U)) {
println!("two arg");
},
fn<T, U, W>(x: (T, U, W)) {
println!("three arg");
},
fn<T, U, W, Q>(x: (T, U, W, Q)) {
println!("way too many arg");
}
}
frunk, but be warned, it isn't that easy to use. Lots of type-level machinery, and it increases compile times quite a lot when used in more than a few places.
What’s your use case? Do you expect all values to be of the same type? If so, could a Vec work for you? If not, you’re entering curious realms where the kinds of things you can do with arbitrary collections of values of arbitrary types are limited.