Is it possible to overload a function with different numbers of arguments (using traits)
I'm trying to have a new constructor with one and with two arguments, but I can't seem to figure out how to do this. Is this even possible at the moment?
What I have now gives me an error that multiple applicable items are in scope (playground)
trait __Constructor1 {
fn new(T) -> Self;
}
trait __Constructor2 {
fn new(T, U) -> Self;
}
enum MixedInts {
SmallInt(i32),
TwoSmallInts(i32, i32),
}
impl __Constructor1 for MixedInts {
fn new(__0: i32) -> MixedInts {
MixedInts::SmallInt(__0)
}
}
impl __Constructor2 for MixedInts {
fn new(__0: i32, __1: i32) -> MixedInts {
MixedInts::TwoSmallInts(__0, __1)
}
}
fn main() {
let x = MixedInts::new(2i32);
let y = MixedInts::new(2i32, 2i32);
}