Skip to content

Document the "as _" (as-underscore) syntax for value coercion / type casting #78042

New issue

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

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

Already on GitHub? # to your account

Closed
cher-nov opened this issue Oct 17, 2020 · 4 comments · Fixed by #78086
Closed

Document the "as _" (as-underscore) syntax for value coercion / type casting #78042

cher-nov opened this issue Oct 17, 2020 · 4 comments · Fixed by #78086
Assignees
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools

Comments

@cher-nov
Copy link

cher-nov commented Oct 17, 2020

I'm pretty sorry if I've somehow missed that somewhere in the official docs.
But that really stumbled me for a hour just now.

This syntax is mentioned there in the opening post, for example:
#45480

@jonas-schievink
Copy link
Contributor

as is documented here: https://doc.rust-lang.org/std/keyword.as.html

It could explicitly mention that the destination type can be an _ placeholder.

@cher-nov
Copy link
Author

It could explicitly mention that the destination type can be an _ placeholder.

I think, it would be also nice to clarify similarities and differences between as / From:: and as _ / .into().

@jyn514 jyn514 added A-coercions Area: implicit and explicit `expr as Type` coercions A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Oct 17, 2020
@poliorcetics
Copy link
Contributor

@rustbot claim

as / From:: and as _ / .into().

I don't think I understand what you want to say with this part. From and Into are (to me) two halves of the same coin, no ?

@cher-nov
Copy link
Author

I don't think I understand what you want to say with this part. From and Into are (to me) two halves of the same coin, no ?

They are. But From:: requires type to be explicitly specified, while .into() inferences it, don't they?
Which is like specifying type in as T and omitting it in as _.

@bors bors closed this as completed in 772b1a6 Nov 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants