@@ -63,11 +63,12 @@ Before describing the syntax in more detail, here's a few sample searches of
63
63
the standard library and functions that are included in the results list:
64
64
65
65
| Query | Results |
66
- | -------| --------|
66
+ | -------| --------- |
67
67
| [ ` usize -> vec ` ] [ ] | ` slice::repeat ` and ` Vec::with_capacity ` |
68
68
| [ ` vec, vec -> bool ` ] [ ] | ` Vec::eq ` |
69
69
| [ ` option<T>, fnonce -> option<U> ` ] [ ] | ` Option::map ` and ` Option::and_then ` |
70
- | [ ` option<T>, fnonce -> option<T> ` ] [ ] | ` Option::filter ` and ` Option::inspect ` |
70
+ | [ ` option<T>, (fnonce (T) -> bool) -> option<T> ` ] [ optionfilter ] | ` Option::filter ` |
71
+ | [ ` option<T>, (T -> bool) -> option<T> ` ] [ optionfilter2 ] | ` Option::filter ` |
71
72
| [ ` option -> default ` ] [ ] | ` Option::unwrap_or_default ` |
72
73
| [ ` stdout, [u8] ` ] [ stdoutu8 ] | ` Stdout::write ` |
73
74
| [ ` any -> ! ` ] [ ] | ` panic::panic_any ` |
@@ -77,7 +78,8 @@ the standard library and functions that are included in the results list:
77
78
[ `usize -> vec` ] : ../../std/vec/struct.Vec.html?search=usize%20-%3E%20vec&filter-crate=std
78
79
[ `vec, vec -> bool` ] : ../../std/vec/struct.Vec.html?search=vec,%20vec%20-%3E%20bool&filter-crate=std
79
80
[ `option<T>, fnonce -> option<U>` ] : ../../std/vec/struct.Vec.html?search=option<T>%2C%20fnonce%20->%20option<U>&filter-crate=std
80
- [ `option<T>, fnonce -> option<T>` ] : ../../std/vec/struct.Vec.html?search=option<T>%2C%20fnonce%20->%20option<T>&filter-crate=std
81
+ [ optionfilter ] : ../../std/vec/struct.Vec.html?search=option<T>%2C+(fnonce+(T)+->+bool)+->+option<T>&filter-crate=std
82
+ [ optionfilter2 ] : ../../std/vec/struct.Vec.html?search=option<T>%2C+(T+->+bool)+->+option<T>&filter-crate=std
81
83
[ `option -> default` ] : ../../std/vec/struct.Vec.html?search=option%20-%3E%20default&filter-crate=std
82
84
[ `any -> !` ] : ../../std/vec/struct.Vec.html?search=any%20-%3E%20!&filter-crate=std
83
85
[ stdoutu8 ] : ../../std/vec/struct.Vec.html?search=stdout%2C%20[u8]&filter-crate=std
@@ -151,16 +153,26 @@ will match these queries:
151
153
152
154
But it * does not* match ` Result<Vec, u8> ` or ` Result<u8<Vec>> ` .
153
155
156
+ To search for a function that accepts a function as a parameter,
157
+ like ` Iterator::all ` , wrap the nested signature in parenthesis,
158
+ as in [ ` Iterator<T>, (T -> bool) -> bool ` ] [ iterator-all ] .
159
+ You can also search for a specific closure trait,
160
+ such as ` Iterator<T>, (FnMut(T) -> bool) -> bool ` ,
161
+ but you need to know which one you want.
162
+
163
+ [ iterator-all ] : ../../std/vec/struct.Vec.html?search=Iterator<T>%2C+(T+->+bool)+->+bool&filter-crate=std
164
+
154
165
### Primitives with Special Syntax
155
166
156
- | Shorthand | Explicit names |
157
- | --------- | ------------------------------------------------ |
158
- | ` [] ` | ` primitive:slice ` and/or ` primitive:array ` |
159
- | ` [T] ` | ` primitive:slice<T> ` and/or ` primitive:array<T> ` |
160
- | ` () ` | ` primitive:unit ` and/or ` primitive:tuple ` |
161
- | ` (T) ` | ` T ` |
162
- | ` (T,) ` | ` primitive:tuple<T> ` |
163
- | ` ! ` | ` primitive:never ` |
167
+ | Shorthand | Explicit names |
168
+ | ---------------- | ------------------------------------------------- |
169
+ | ` [] ` | ` primitive:slice ` and/or ` primitive:array ` |
170
+ | ` [T] ` | ` primitive:slice<T> ` and/or ` primitive:array<T> ` |
171
+ | ` () ` | ` primitive:unit ` and/or ` primitive:tuple ` |
172
+ | ` (T) ` | ` T ` |
173
+ | ` (T,) ` | ` primitive:tuple<T> ` |
174
+ | ` ! ` | ` primitive:never ` |
175
+ | ` (T, U -> V, W) ` | ` fn(T, U) -> (V, W) ` , ` Fn ` , ` FnMut ` , and ` FnOnce ` |
164
176
165
177
When searching for ` [] ` , Rustdoc will return search results with either slices
166
178
or arrays. If you know which one you want, you can force it to return results
@@ -180,6 +192,10 @@ results for types that match tuples, even though it also matches the type on
180
192
its own. That is, ` (u32) ` matches ` (u32,) ` for the exact same reason that it
181
193
also matches ` Result<u32, Error> ` .
182
194
195
+ The ` -> ` operator has lower precedence than comma. If it's not wrapped
196
+ in brackets, it delimits the return value for the function being searched for.
197
+ To search for functions that take functions as parameters, use parenthesis.
198
+
183
199
### Limitations and quirks of type-based search
184
200
185
201
Type-based search is still a buggy, experimental, work-in-progress feature.
@@ -218,9 +234,6 @@ Most of these limitations should be addressed in future version of Rustdoc.
218
234
219
235
* Searching for lifetimes is not supported.
220
236
221
- * It's impossible to search for closures based on their parameters or
222
- return values.
223
-
224
237
* It's impossible to search based on the length of an array.
225
238
226
239
## Item filtering
@@ -237,19 +250,21 @@ Item filters can be used in both name-based and type signature-based searches.
237
250
238
251
``` text
239
252
ident = *(ALPHA / DIGIT / "_")
240
- path = ident *(DOUBLE-COLON ident) [! ]
253
+ path = ident *(DOUBLE-COLON ident) [BANG ]
241
254
slice-like = OPEN-SQUARE-BRACKET [ nonempty-arg-list ] CLOSE-SQUARE-BRACKET
242
255
tuple-like = OPEN-PAREN [ nonempty-arg-list ] CLOSE-PAREN
243
- arg = [type-filter *WS COLON *WS] (path [generics] / slice-like / tuple-like / [!] )
256
+ arg = [type-filter *WS COLON *WS] (path [generics] / slice-like / tuple-like)
244
257
type-sep = COMMA/WS *(COMMA/WS)
245
- nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep)
258
+ nonempty-arg-list = *(type-sep) arg *(type-sep arg) *(type-sep) [ return-args ]
246
259
generic-arg-list = *(type-sep) arg [ EQUAL arg ] *(type-sep arg [ EQUAL arg ]) *(type-sep)
247
- generics = OPEN-ANGLE-BRACKET [ generic-arg-list ] *(type-sep)
260
+ normal- generics = OPEN-ANGLE-BRACKET [ generic-arg-list ] *(type-sep)
248
261
CLOSE-ANGLE-BRACKET
262
+ fn-like-generics = OPEN-PAREN [ nonempty-arg-list ] CLOSE-PAREN [ RETURN-ARROW arg ]
263
+ generics = normal-generics / fn-like-generics
249
264
return-args = RETURN-ARROW *(type-sep) nonempty-arg-list
250
265
251
266
exact-search = [type-filter *WS COLON] [ RETURN-ARROW ] *WS QUOTE ident QUOTE [ generics ]
252
- type-search = [ nonempty-arg-list ] [ return-args ]
267
+ type-search = [ nonempty-arg-list ]
253
268
254
269
query = *WS (exact-search / type-search) *WS
255
270
@@ -294,6 +309,7 @@ QUOTE = %x22
294
309
COMMA = ","
295
310
RETURN-ARROW = "->"
296
311
EQUAL = "="
312
+ BANG = "!"
297
313
298
314
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
299
315
DIGIT = %x30-39
0 commit comments