about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/externs.js
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-06-27 11:07:16 -0700
committerMichael Howell <michael@notriddle.com>2022-06-27 11:07:16 -0700
commit8081096a7f9b84fe780f4426d70f4c5bb767eba8 (patch)
tree66c49a945008a9d899d3f4e37abfce26316876e7 /src/librustdoc/html/static/js/externs.js
parent5deb396630f2cdaad85f94b558f34a236d284b94 (diff)
downloadrust-8081096a7f9b84fe780f4426d70f4c5bb767eba8.tar.gz
rust-8081096a7f9b84fe780f4426d70f4c5bb767eba8.zip
Add documentation
Diffstat (limited to 'src/librustdoc/html/static/js/externs.js')
-rw-r--r--src/librustdoc/html/static/js/externs.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/externs.js b/src/librustdoc/html/static/js/externs.js
index defdc20132e..141d76d59e1 100644
--- a/src/librustdoc/html/static/js/externs.js
+++ b/src/librustdoc/html/static/js/externs.js
@@ -81,3 +81,56 @@ let ResultsTable;
  * }}
  */
 let Results;
+
+/**
+ * A pair of [inputs, outputs], or 0 for null. This is gets stored in the search index.
+ * The JavaScript deserializes this into FunctionSearchType.
+ *
+ * An input or output can be encoded as just a number if there is only one of them, AND
+ * it has no generics. The no generics rule exists to avoid ambiguity: imagine if you had
+ * a function with a single output, and that output had a single generic:
+ *
+ *     fn something() -> Result<usize, usize>
+ *
+ * If output was allowed to be any RawFunctionType, it would look like this
+ *
+ *     [[], [50, [3, 3]]]
+ *
+ * The problem is that the above output could be interpreted as either a type with ID 50 and two
+ * generics, or it could be interpreted as a pair of types, the first one with ID 50 and the second
+ * with ID 3 and a single generic parameter that is also ID 3. We avoid this ambiguity by choosing
+ * in favor of the pair of types interpretation. This is why the `(number|Array<RawFunctionType>)`
+ * is used instead of `(RawFunctionType|Array<RawFunctionType>)`.
+ *
+ * @typedef {(
+ *     0 |
+ *     [(number|Array<RawFunctionType>)] |
+ *     [(number|Array<RawFunctionType>), (number|Array<RawFunctionType>)]
+ * )}
+ */
+let RawFunctionSearchType;
+
+/**
+ * A single function input or output type. This is either a single path ID, or a pair of
+ * [path ID, generics].
+ *
+ * @typedef {number | [number, Array<RawFunctionType>]}
+ */
+let RawFunctionType;
+
+/**
+ * @typedef {{
+ *     inputs: Array<FunctionType>,
+ *     outputs: Array<FunctionType>,
+ * }}
+ */
+let FunctionSearchType;
+
+/**
+ * @typedef {{
+ *     name: (null|string),
+ *     ty: (null|number),
+ *     generics: Array<FunctionType>,
+ * }}
+ */
+let FunctionType;