Skip to content

Conversation

@wiiznokes
Copy link

previous pr: #553

todo:

  • add more test cases (currently, only Enum::A pass)
  • handle all struct type in handle_any_struct
  • finish implementing visit_enum
  • impl Serialize for Value
  • clean up code
  • I've included my change in CHANGELOG.md

@wiiznokes
Copy link
Author

honestly, after having passed way to much time on this, i think its just not possible.
We just need to attach a name to Tuple and Map.
To create a Value, we need a Visitor. The only method capable of this in Visitor is visit_enum.

But,

  • the visitor must be generic. It doesn't know in advance the type of the enum.
  • the VariantAccess trait have
    fn unit_variant(self) -> Result<(), Self::Error>;
    fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error>
    fn tuple_variant<V>(self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
    fn struct_variant<V>(
          self,
          fields: &'static [&'static str],
          visitor: V,
       ) -> Result<V::Value, Self::Error>
    all this method take self, so we can't all call them to know what is the type of the enum.

So we are cooked. I wonder if a language succeed to do this. Maybe i can be proven wrong.

I think we just need another method on VariantAccess:

fn enum_type(&self) -> Option<EnumType>;
enum EnumType {
    Unit,
    NewType,
    Tuple,
    Struct
}

@wiiznokes
Copy link
Author

serde-rs/serde#2874

@juntyr
Copy link
Member

juntyr commented Jul 26, 2025

Thank you for exploring it further @wiiznokes! I personally think that many improvements are still blocked on serde, perhaps we can come back to this once ron is given more agency in deserialising data without type information

@wiiznokes
Copy link
Author

wiiznokes commented Jul 26, 2025

Another solution could be to not implement Deserialize for Value. I don't think it's very used in its current shape anyway since it doesn't store enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants