diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 84d684e0c95f..52617b6c4320 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -61,6 +61,8 @@
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::symbol::{Symbol, sym};
use rustc_span::{BytePos, DUMMY_SP, FileName, RealFileName};
+use serde::ser::SerializeSeq as _;
+use serde::{Deserialize, Serialize};
use tracing::{debug, info};
pub(crate) use self::context::*;
@@ -144,7 +146,7 @@ pub(crate) struct IndexItem {
}
/// A type used for the search index.
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Clone, Debug, Eq, PartialEq)]
struct RenderType {
id: Option,
generics: Option>,
@@ -301,7 +303,7 @@ fn read_from_bytes(string: &[u8]) -> (Option, usize) {
}
/// Full type of functions/methods in the search index.
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct IndexItemFunctionType {
inputs: Vec,
output: Vec,
@@ -423,6 +425,75 @@ fn write_to_string_without_param_names<'a>(&'a self, string: &mut String) {
}
}
+impl Serialize for IndexItemFunctionType {
+ fn serialize(&self, serializer: S) -> Result
+ where
+ S: serde::Serializer,
+ {
+ let mut seq = serializer.serialize_seq(Some(2))?;
+ let mut fn_type = String::new();
+ self.write_to_string_without_param_names(&mut fn_type);
+ seq.serialize_element(&fn_type)?;
+
+ struct ParamNames<'a>(&'a [Option]);
+
+ impl<'a> Serialize for ParamNames<'a> {
+ fn serialize(&self, serializer: S) -> Result
+ where
+ S: serde::Serializer,
+ {
+ serializer.collect_seq(
+ self.0
+ .iter()
+ .map(|symbol| symbol.as_ref().map(ToString::to_string).unwrap_or_default()),
+ )
+ }
+ }
+
+ seq.serialize_element(&ParamNames(&self.param_names))?;
+ seq.end()
+ }
+}
+
+impl<'de> Deserialize<'de> for IndexItemFunctionType {
+ fn deserialize(deserializer: D) -> Result
+ where
+ D: serde::Deserializer<'de>,
+ {
+ use serde::de::{self, Error as _};
+
+ struct FunctionDataVisitor;
+ impl<'de> de::Visitor<'de> for FunctionDataVisitor {
+ type Value = IndexItemFunctionType;
+ fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> fmt::Result {
+ write!(formatter, "fn data")
+ }
+ fn visit_seq>(self, mut v: A) -> Result {
+ let (mut function_signature, _) = v
+ .next_element()?
+ .map(|fn_: String| {
+ IndexItemFunctionType::read_from_string_without_param_names(fn_.as_bytes())
+ })
+ .ok_or_else(|| A::Error::missing_field("function_signature"))?;
+ let param_names: Vec