The last few days I was thinking if it could be possible to implement variadics in Rust and today I sat down and tried to implement it.
It should be nothing more than a small fun project and I uploaded it on github GitHub - MaikKlein/variadic: Variadics in stable Rust
The code is small enough for the playground
Shortly afterwards I discovered a flaw
fn debug_print<T, Args: Variadic<T>>(args: Args)
where T: std::fmt::Debug
{
if let (Some(front), rest) = args.pop() {
println!("{:?}", front);
debug_print(rest);
}
}
This doesn't work if I call debug_print
with different types. I know that I probably push the type system too much but the error messages are getting a bit cryptic
error[E0277]: the trait bound `VarArgs2<{integer}, {float}>: Variadic<_>` is not satisfied
--> <anon>:58:5
|
58 | debug_print(VarArgs2(1, 1.0));
| ^^^^^^^^^^^ trait `VarArgs2<{integer}, {float}>: Variadic<_>` not satisfied
|
= help: the following implementations were found:
= help: <VarArgs2<T, A> as Variadic<T, A>>
= note: required by `debug_print`
The problem is Variadic<_>
, which is not very helpful. Maybe any of you know what is going on?