-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Replace use id = path;
with use path as id;
#169
Conversation
Alternative syntax (which I find more natural) is to use fat arrow: use a::{b => c, d => e}; Such syntax is used in Scala: import java.util.{List => JList} In Scala it does require boundaries (that is, curly braces) around it, but this restriction may be lifted off in Rust when there is only one identifier imported: use a::b::c => d; |
A general comment: this syntax seems like it would generalise to multiple renamings (that is, I did a quick survey of how one aliases imports in a variety of (popularish) languages, just to try to gauge if any form has overwhelming support outside Rust (spoilers: no):
|
I am generally in favor of this minor adjustment, but with the caveat that this should also then be done for |
Go ahead with switch, so imported identifier is on the left-hand side, | ||
but use a different token than `as` to signal a rebinding. | ||
|
||
For example, we could use `@`, as an analogy with its use as a binding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… except for the minor matter that the binding operator in match expressions has the identifier on the left, not the right. (Yeah, this has always struck me as back-to-front and I wonder whether we should swap it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB. this is taken directly from Haskell's as patterns, including the current binding order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s what I had understood. I still think it should probably be changed. (Or even replace @
with =
, then the order would make sense.) Anyway, that’s outside the scope of this issue.
I am strongly in favour of this, including @SiegeLord’s addendum. It makes our syntax around this stuff closer to Python’s, also, which is in my opinion good. |
Another data point in the survey: ES6 modules have the syntaxes |
I think I like this, along with @huonw's idea of generalizing it to |
There is a grammatical difficulty in patterns related to identifiers and types. Casting |
@pczarn I'm afraid I don't completely understand.
I tried a few different ways, and could not get
I was not aware of expressions being currently allowed in patterns at all. I think they're not, but feel free to correct me. And patterns are precisely where (I suspect there must be something very basic which I'm missing or misunderstanding.) |
Much more in favor of the "as" syntax then the |
@glaebhoerl, my mistake, it's not a grammatical issue. But consider the following shadowing: match 1234 {
int @ 1234 => int,
_ => 0
} It gets much worse when the meaning of match 1234 {
1234 as int => int,
_ => 0
} |
@pczarn I think naming your variables |
+1 very neat. Good points:
|
@SiegeLord I agree, it seems reasonable to apply the same change to the |
a big +1, i like this! thank you. For the current syntax, |
This sounds nice. It's a small but worthy increase in usability. |
I wholeheartedly agree with @liigo that this change would make it much more intuitive as to which name is the original. +1 |
+1 as well, use path::old_name;
use path::old_name as new_name;
extern crate old_name;
extern crate old_name as new_name; // Support ident case for simple renaming
extern crate "old_name" as new_name; // Support string case for arbitrary library name Given the choice between I also think whether or not a |
@Kimundi Hmm I have not considered three variants for |
Note that I only put it in the Alternatives. I think there is a pretty good argument that whether to do this or not is orthogonal to this RFC, and the only reason to fold it into this RFC is to avoid the process overhead of filing a seprate RFC.
(merged as RFC 47) |
Summary: Change the rebinding syntax from
use ID = PATH
touse PATH as ID
, so that paths all line up on the left side, and imported identifers are all on the right side. Also modifyextern crate
syntaxanalogously, for consistency.
Rendered view