0xedb
0xedb

Reputation: 364

What is this `impl<A, B, C, D, E, F, G, H, I, J> Default for (A, B, C, D, E, F, G, H, I, J)`

Found this in the default trait documentation and wondering what it is:

impl<A, B, C, D, E, F, G, H, I, J> Default for (A, B, C, D, E, F, G, H, I, J)
where
    A: Default,
    B: Default,
    C: Default,
    D: Default,
    E: Default,
    F: Default,
    G: Default,
    H: Default,
    I: Default,
    J: Default, 

Is this important in any way?

Reference: https://doc.rust-lang.org/std/default/trait.Default.html#impl-Default-63

Upvotes: 0

Views: 790

Answers (1)

Here, Default trait is implemented for any tuple struct with 10 elements where each element implements Default. This is ugly, but I suppose there is no better way to express this in the language. It is repeated for other number of elements in the same file too.

I can't name any, but I have seen such generic definition repetitions elsewhere in Rust std lib. Later some were expressed better with new language features. You can probably find other examples by searching macro_rules within the standard library source code.

Edit: If one day Variadic generics comes to Rust, it would provide an idiomatic way to implement a trait for arbitrary tuples.

See: About variadics in Rust

Upvotes: 4

Related Questions