serde
serde copied to clipboard
Name of the type in generated Deserializer::deserialize_* calls for remote types
I noted, that when you derive remote deserialization, the name passed to the deserializer is the name of the Self type and not the name of the remote type. At the same time the error message in Visitor implementations uses the name of the remote type:
#[derive(serde::Deserialize)]
#[serde(remote = "Unit")]
struct RemoteUnit;
expands to (littly reformatted for readability)
#[serde(remote = "Unit")]
struct RemoteUnit;
#[automatically_derived]
impl<'de> RemoteUnit {
fn deserialize<D>(deserializer: D) -> Result<Unit, D::Error>
where
D: Deserializer<'de>,
{
#[doc(hidden)]
struct Visitor<'de> {
marker: PhantomData<Unit>,
lifetime: PhantomData<&'de ()>,
}
#[automatically_derived]
impl<'de> de::Visitor<'de> for Visitor<'de> {
type Value = Unit;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("unit struct Unit") //<<< HERE the name of the remote type is used
}
#[inline]
fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(Unit)
}
}
deserializer.deserialize_unit_struct(
"RemoteUnit", //<<< HERE the name of the Self type is used
Visitor {
marker: PhantomData::<Unit>,
lifetime: PhantomData,
},
)
}
}
It seems to me that both names should be equal. This is happens for any type form, not just Units.