Hello, I recently discussed on the subreddit[1], why is it not possible to have an use statement inside of the impl block, which would be extremely handy, mainly in enumeration implementations.
For clearance, effect of the use statement would be inside of the implementation block, same as is with the mod block, so imported names would be visible in all methods defined in the implementation block, without contaminating whole module, in which the enumeration is defined:
enum List<T> {
Cons {
value: T,
next: Box<List<T>>,
},
Nil,
}
impl<T> List<T> {
use crate::LinkedList::*;
pub fn empty() -> Self {
Nil
}
}
Thanks & Cheers !
[1] https://www.reddit.com/r/rust/comments/axzcmb/why_is_use_statement_not_allowed_in_impl_block/