6 ms·
If you’re using rust-analyzer in your editor of choice, it will often suggest and auto-import traits when you try to use their methods with the trait not in sco
by mplanchard 5y ago
If you’re using rust-analyzer in your editor of choice, it will often suggest and auto-import traits when you try to use their methods with the trait not in scope. It knows, based on the dependency graph and your own code, all of the traits that could provide a method.
I use rust-analyzer in emacs, but it’s available in any editor that supports language servers.
With my setup, I’ll start typing a method, get a completion for the trait method I want with the trait indicated, and select the completion. The trait is then automatically imported and the method is completed.
- camgunz 5y agorust-analyzer is a language server, which (along with autocomplete and maybe infuriatingly) I'm not into. I think this mostly reinforces Eli's point, which is broadly that you need a lot of editor support to use Rust reasonably ergonomically.
- mplanchard 5y agoI think the sibling comment pointing out that the compiler errors tell you exactly what trait you need is for you then! You can get them with just a `cargo check`, no language server required.