Recently I start learning embedded examples and rust language in general. I don't read the rust book yet, only on chapter 10.
Came across an example of a non-explicit import..
Without implicit import of trait:
use embedded_hal::delay::DelayNs;
I get an error when trying to call delay method:
timer.delay_ms(100);
E0599 no method named delay_ms found for struct Timer in the current scope items from traits can only be used if the trait is in scope.
Error description seems good, this is not the deal.
But after some time, when I look for my use statements - I cannot tell, what code use embedded_hal::delay::DelayNs. Only if I delete it and check what breaks after it.
I thought hole idea of use statements to bring library code explicit and use it that way. But in this example - some use statements brings traits to scope, and some code use them implicitly. That creates some confusion.
You're right, it does create some confusion. As you use Rust more, hopefully you'll become accustomed to it.
The best way to know whether an import can be deleted is to rely on the compiler's unused warnings. If you're using an editor with rust-analyzer, these warnings will also be highlighted in the editor.
I strongly recommend relying on the unused warning. It tells you whether dead code can be removed as well. I rely on it heavily.