Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow use self with globs #1290

Closed
mdinger opened this issue Sep 22, 2015 · 6 comments
Closed

allow use self with globs #1290

mdinger opened this issue Sep 22, 2015 · 6 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@mdinger
Copy link
Contributor

mdinger commented Sep 22, 2015

Importing all the subnames of a module is easily done with globs but if you also want to import the module, then you need 2 separate lines to do so:

use my_mod::*;
use my_mod;

Without globs it's not an issues:

use my_mod::{self, foo, bar, baz};

It would be convenient to allow globs to import the module on the same line as well. Here are some possible syntaxes which (I think) could be understandable:

use my_mod::{self, *};
use my_mod::+;

+ is mainly because * and + are common with globs. + typically means one or more while * is any number of elements so they aren't exactly similar but it doesn't seem too unusual.

@Kimundi
Copy link
Member

Kimundi commented Sep 23, 2015

I think that this use case is obscure enough that enabling a composition like use my_mod::{self, *}; is the far better alternative than new syntax, if it should be allowed at all.

@codyps
Copy link

codyps commented Sep 23, 2015

I like use my_mod::{self, *} too.

@mdinger
Copy link
Contributor Author

mdinger commented Sep 23, 2015

@Kimundi That's pretty fair. It could always be added later too if it was really desired which I'm not certain it is.

@withoutboats
Copy link
Contributor

I think {self, *} should definitely be possible, but this seems like a really uncommon case. Why would you want to import the module AND everything in the module?

@mdinger
Copy link
Contributor Author

mdinger commented Sep 23, 2015

@withoutboats Eh, I think I've done it before but I can't find any. Anyway, maybe you're writing lots of tests and you use globs for convenience for importing types but your preference is to call functions through the module (maybe functions didn't used to be importable through use but now they can...). Maybe it's quick and dirty when you've got {self, A, B, C, D, E} and things are being shuffled so you just up and replace it with {self, *}. Then fix it later.

@withoutboats
Copy link
Contributor

A case where this would be useful would be enabling enum imports:

use std::option::Option::{self, *};.

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants