@@ -72,6 +72,7 @@ the standard library and functions that are included in the results list:
72
72
| [ ` stdout, [u8] ` ] [ stdoutu8 ] | ` Stdout::write ` |
73
73
| [ ` any -> ! ` ] [ ] | ` panic::panic_any ` |
74
74
| [ ` vec::intoiter<T> -> [T] ` ] [ iterasslice ] | ` IntoIter::as_slice ` and ` IntoIter::next_chunk ` |
75
+ | [ ` iterator<T>, fnmut -> T ` ] [ iterreduce ] | ` Iterator::reduce ` and ` Iterator::find ` |
75
76
76
77
[ `usize -> vec` ] : ../../std/vec/struct.Vec.html?search=usize%20-%3E%20vec&filter-crate=std
77
78
[ `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:
81
82
[ `any -> !` ] : ../../std/vec/struct.Vec.html?search=any%20-%3E%20!&filter-crate=std
82
83
[ stdoutu8 ] : ../../std/vec/struct.Vec.html?search=stdout%2C%20[u8]&filter-crate=std
83
84
[ 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
84
86
85
87
### How type-based search works
86
88
@@ -95,16 +97,47 @@ After deciding which items are type parameters and which are actual types, it
95
97
then searches by matching up the function parameters (written before the ` -> ` )
96
98
and the return types (written after the ` -> ` ). Type matching is order-agnostic,
97
99
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.
99
103
100
104
Function signature searches can query generics, wrapped in angle brackets, and
101
105
traits will be normalized like types in the search engine if no type parameters
102
106
match them. For example, a function with the signature
103
107
` fn my_function<I: Iterator<Item=u32>>(input: I) -> usize `
104
108
can be matched with the following queries:
105
109
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.
117
+
118
+ If a bound has multiple associated types, specifying the name allows you to
119
+ pick which one gets matched. If no name is specified, then the query will
120
+ match of any of them. For example,
121
+
122
+ ``` rust
123
+ pub trait MyTrait {
124
+ type First ;
125
+ type Second ;
126
+ }
127
+
128
+ /// This function can be found using the following search queries:
129
+ ///
130
+ /// MyTrait<First=u8, Second=u32> -> bool
131
+ /// MyTrait<u32, First=u8> -> bool
132
+ /// MyTrait<Second=u32> -> bool
133
+ /// MyTrait<u32, u8> -> bool
134
+ ///
135
+ /// The following queries, however, will *not* match it:
136
+ ///
137
+ /// MyTrait<First=u32> -> bool
138
+ /// MyTrait<u32, u32> -> bool
139
+ pub fn my_fn (x : impl MyTrait <First = u8 , Second = u32 >) -> bool { true }
140
+ ```
108
141
109
142
Generics and function parameters are order-agnostic, but sensitive to nesting
110
143
and number of matches. For example, a function with the signature
@@ -134,6 +167,10 @@ Most of these limitations should be addressed in future version of Rustdoc.
134
167
with that bound, it'll match, but ` option<T> -> T where T: Default `
135
168
cannot be precisely searched for (use ` option<Default> -> Default ` ).
136
169
170
+ * Supertraits, type aliases, and Deref are all ignored. Search mostly
171
+ operates on type signatures * as written* , and not as they are
172
+ represented within the compiler.
173
+
137
174
* Type parameters match type parameters, such that ` Option<A> ` matches
138
175
` Option<T> ` , but never match concrete types in function signatures.
139
176
A trait named as if it were a type, such as ` Option<Read> ` , will match
@@ -183,7 +220,8 @@ slice = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
183
220
arg = [type-filter *WS COLON *WS] (path [generics] / slice / [!])
184
221
type-sep = COMMA/WS *(COMMA/WS)
185
222
nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
186
- generics = OPEN-ANGLE-BRACKET [ nonempty-arg-list ] *(type-sep)
223
+ generic-arg-list = *(type-sep) arg [ EQUAL arg ] *(type-sep arg [ EQUAL arg ]) *(type-sep)
224
+ generics = OPEN-ANGLE-BRACKET [ generic-arg-list ] *(type-sep)
187
225
CLOSE-ANGLE-BRACKET
188
226
return-args = RETURN-ARROW *(type-sep) nonempty-arg-list
189
227
@@ -230,6 +268,7 @@ DOUBLE-COLON = "::"
230
268
QUOTE = %x22
231
269
COMMA = ","
232
270
RETURN-ARROW = "->"
271
+ EQUAL = "="
233
272
234
273
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
235
274
DIGIT = %x30-39
0 commit comments