Anonymous trait use

Traits are often imported only for their methods, the trait name itself being unused. When the trait name conflicts with some other type or trait, it has to be given an alias with as.

Another issue with trait use is, it’s hard to see which of the names in the use items identify traits. So unless one uses an editor with code indexing functionality, it’s more difficult to find the origin of a trait-supplied method among all the used names.

To help set the traits apart and reduce the namespace pollution, it might be useful to import traits anonymously. I can suggest two variants of syntax:

use Tr as _;

or more descriptively:

use trait Tr;
2 Likes

You can already do use Tr as _ AFAIK

No, it fails compilation with "error: expected ident, found _" as of rustc 0.13.0-nightly (c6c786671 2015-01-04 00:50:59 +0000)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.