I found this question on the Rust users forum : Generics: Can I say "tuple where each element is FromSql". Basically, the questions was to know how do something like that :
trait Foo {}
struct A {}
impl Foo for A {}
struct B {}
impl Foo for B {}
fn main() {
let x = (A{}, A{}, B{}, A{});
bar(x);
}
fn bar<T: Foo>(tuple: (T...)) {
}
This code does not work, it's an idea of how it could look like.
So, how can we do that?
ToAnytrait that will be implemented for all our structures.The implementation of
ToAnyis always the same, we could create a macro implementing it easily.Vecinstead of a tuple to store our values:If we refer to the question, the following code:
can be this valid code:
I've written a gist file being tests for that. Be careful, I've changed the names in this post,
FooisAand there is only theBstructure.