Type annotation for trait method call

I'm a rust beginner, and this is not a blocking point but is of interest in my learning.
I defined a trait AsfaloadKeyPair which defines a method new. I implemented the trait for minisign::KeyPair so I can call

let kp = minisign::KeyPair::new("mypass")?.save(temp_file_path)?;

I'm wondering if there's a way to call new from the AsfaloadKeyPair trait itself, like:

let kp: &minisign::KeyPair = AsfaloadKeyPair::new("mypass")?.save(temp_file_path)?;

But this doesn't work as it asks for a type annotation on AsfaloadKeyPair::new("mypass")?. How do you give this expression a type annotation?

Thanks!

what do you mean by "from the trait itself"? if you are defining the default implementation for some of the trait method, you can use Self::new, or <Self as AsfaloadKeyPair>::new.

If you want to, you can specify the type and the trait simultaneously with:

<minisign::KeyPair as AsfaloadKeyPair>::new("mypass")

It should also work to constrain the return type immediately, before performing a method call on it:

let kp: minisign::KeyPair = AsfaloadKeyPair::new("mypass")?;