Type annotation for trait method call
⚓ Rust 📅 2025-06-23 👤 surdeus 👁️ 15I'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!
2 posts - 2 participants
🏷️ rust_feed