serde icon indicating copy to clipboard operation
serde copied to clipboard

Conflicting `DeserializeSeed` impls for different deserializable types with the same seed type

Open starptr opened this issue 1 year ago • 1 comments

Consider this struct:

struct B {
  c: ComplicatedType,
}

We have that ComplicatedType has a DeserializableSeed implementation for a seed of type &Seed. Therefore, struct B should have a DeserializableSeed implementation for a seed of type &Seed. However, when I try to do so:

impl<'de> DeserializeSeed<'de> for &SeedT {
  type Value = ComplicatedType;
  …
}

impl<'de> DeserializeSeed<'de> for &SeedT {
  type Value = B;
  …
}

this is an error because we are impling the same trait for the same seed twice. What's a good way to go about this?

More generally, is it possible to automatically derive (or minimize boilerplate for) DeserializeSeed for some type T wrt. a particular seed S when all of the inner types of T are already either Deserialize or DeserializeSeed wrt. S?

starptr avatar Dec 29 '24 00:12 starptr

You might be interested in https://docs.rs/serde-seeded/latest/serde_seeded and https://docs.rs/serde_state/latest/serde_state which try to do this.

Nadrieril avatar Nov 29 '25 19:11 Nadrieril