Skip to content

Commit a2d247b

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

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 path_, a means of clarifying ambiguous method calls, constants, and types.
29+
/// If you have a type which implements two traits with identical method names (e.g.
30+
/// `Into<u32>::into` and `Into<u64>::into`), you can clarify which method you'll use with
31+
/// `<MyThing as Into<u32>>::into(my_thing)`. This is quite verbose, but fortunately, Rust's type
32+
/// inference usually saves you from needing this, although it 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)