Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7cfd0dd

Browse files
Document fully-qualified syntax in as' keyword doc
1 parent 55d4364 commit 7cfd0dd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎library/std/src/keyword_docs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
/// (`u8`, `bool`, `str`, pointers, ...) whereas `From` and `Into` also works with types like
2525
/// `String` or `Vec`.
2626
///
27+
/// You'll also find with `From` and `Into`, and indeed all traits, that `as` is used for the
28+
/// _fully qualified syntax_, a means of clarifying ambiguous method calls. If you have a type which
29+
/// implements two traits with identical method names (e.g. `Into<u32>` and `Into<u64>`), you can
30+
/// clarify which method you use with `<MyThing as Into<u32>>::into(my_thing)`. This is quite
31+
/// verbose, but fortunately, Rust's type inference usually saves you from needing this, although it
32+
/// is occasionally necessary.
33+
///
2734
/// `as` can also be used with the `_` placeholder when the destination type can be inferred. Note
2835
/// that this can cause inference breakage and usually such code should use an explicit type for
2936
/// both clarity and stability. This is most useful when converting pointers using `as *const _` or

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /