Skip to content

Commit 6837943

Browse files
committed
rustdoc: update book with info on type bindings
1 parent 724749e commit 6837943

File tree

1 file changed

+15
-4
lines changed
  • src/doc/rustdoc/src/read-documentation

1 file changed

+15
-4
lines changed

src/doc/rustdoc/src/read-documentation/search.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ the standard library and functions that are included in the results list:
7272
| [`stdout, [u8]`][stdoutu8] | `Stdout::write` |
7373
| [`any -> !`][] | `panic::panic_any` |
7474
| [`vec::intoiter<T> -> [T]`][iterasslice] | `IntoIter::as_slice` and `IntoIter::next_chunk` |
75+
| [`iterator<T>, fnmut -> T`][iterreduce] | `Iterator::reduce` and `Iterator::find` |
7576

7677
[`usize -> vec`]: ../../std/vec/struct.Vec.html?search=usize%20-%3E%20vec&filter-crate=std
7778
[`vec, vec -> bool`]: ../../std/vec/struct.Vec.html?search=vec,%20vec%20-%3E%20bool&filter-crate=std
@@ -81,6 +82,7 @@ the standard library and functions that are included in the results list:
8182
[`any -> !`]: ../../std/vec/struct.Vec.html?search=any%20-%3E%20!&filter-crate=std
8283
[stdoutu8]: ../../std/vec/struct.Vec.html?search=stdout%2C%20[u8]&filter-crate=std
8384
[iterasslice]: ../../std/vec/struct.Vec.html?search=vec%3A%3Aintoiter<T>%20->%20[T]&filter-crate=std
85+
[iterreduce]: ../../std/index.html?search=iterator<T>%2C%20fnmut%20->%20T&filter-crate=std
8486

8587
### How type-based search works
8688

@@ -95,16 +97,23 @@ After deciding which items are type parameters and which are actual types, it
9597
then searches by matching up the function parameters (written before the `->`)
9698
and the return types (written after the `->`). Type matching is order-agnostic,
9799
and allows items to be left out of the query, but items that are present in the
98-
query must be present in the function for it to match.
100+
query must be present in the function for it to match. The `self` parameter is
101+
treated the same as any other parameter, and `Self` is resolved to the
102+
underlying type's name.
99103

100104
Function signature searches can query generics, wrapped in angle brackets, and
101105
traits will be normalized like types in the search engine if no type parameters
102106
match them. For example, a function with the signature
103107
`fn my_function<I: Iterator<Item=u32>>(input: I) -> usize`
104108
can be matched with the following queries:
105109

106-
* `Iterator<u32> -> usize`
107-
* `Iterator -> usize`
110+
* `Iterator<Item=u32> -> usize`
111+
* `Iterator<u32> -> usize` (you can leave out the `Item=` part)
112+
* `Iterator -> usize` (you can leave out iterator's generic entirely)
113+
* `T -> usize` (you can match with a generic parameter)
114+
115+
Each of the above queries is progressively looser, except the last one
116+
would not match `dyn Iterator`, since that's not a type parameter.
108117

109118
Generics and function parameters are order-agnostic, but sensitive to nesting
110119
and number of matches. For example, a function with the signature
@@ -183,7 +192,8 @@ slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
183192
arg = [type-filter *WS COLON *WS] (path [generics] / slice / [!])
184193
type-sep = COMMA/WS *(COMMA/WS)
185194
nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
186-
generics = OPEN-ANGLE-BRACKET [ nonempty-arg-list ] *(type-sep)
195+
generic-arg-list = *(type-sep) arg [ EQUAL arg ] *(type-sep arg [ EQUAL arg ]) *(type-sep)
196+
generics = OPEN-ANGLE-BRACKET [ generic-arg-list ] *(type-sep)
187197
CLOSE-ANGLE-BRACKET
188198
return-args = RETURN-ARROW *(type-sep) nonempty-arg-list
189199
@@ -230,6 +240,7 @@ DOUBLE-COLON = "::"
230240
QUOTE = %x22
231241
COMMA = ","
232242
RETURN-ARROW = "->"
243+
EQUAL = "="
233244
234245
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
235246
DIGIT = %x30-39

0 commit comments

Comments
 (0)