Type inference for method on generic struct with default types

#1

Hi!

I have code similar to the code at this playground link. Basically, I’d like to be able to write let thing = Thing::new() without having to specify types anywhere. I’ve tried moving the <T = blah> part to different places, but apparently it’s only valid where I put it.

Is there a way I can specify the default type for Thing or fn new() in such a way that I never have to specify the generic type parameters or include : Thing anywhere?

#2

Hi, you can do this.

1 Like
#3

That’s cool, thanks. But suppose I wanted to keep a generic implementation of new() around so that I could still have the option of doing Thing::<SomethingElse1, SE2, Se3>::new()?

#4

I don’t think you can do it exactly as you want it until specialization, in the mean time you can use what you posted or use two functions like that.