Git Product home page Git Product logo

Comments (4)

zrkn avatar zrkn commented on August 19, 2024 1

Agreed. Implemented in separate crate - https://github.com/zrkn/rlua_serde/
Thanks for feedback, I think we can close this.

from rlua.

kyren avatar kyren commented on August 19, 2024

I've definitely had the same idea, it's cool that you implemented this and I'll definitely take a look at it.

The problem with doing this though, is that it creates two paths for serialization, the Serialize / Deserialize path and the ToLua / FromLua path.

If there a way that we could provide some sort of to_lua_serialize! and from_lua_deserialize macros that make a struct that is Serialize / Deserialize implement ToLua / FromLua, that would be really interesting. I haven't looked into it, but I don't think that's possible to do in a way where it forwards to ToLua / FromLua on the fields of the struct implementing Serialize / Deserialize, and if you have two separate serialization systems, I don't think that's going to work out very well.

The problem is something like this, suppose you have a struct Complicated with a bespoke impl ToLua for Complicated and impl FromLua for Complicated. Then, if you have a #[derive(Serialize, Deserialize)] struct Compound { complicated: Complicated }, at best using Serialize / Deserialize to do the Lua conversion won't compile, but at worst it may actually use a serialization that you don't actually want. I don't really want there to be multiple parallel ways to do Lua serialization.

I might be wrong though, and that might be feasible to forward to ToLua / FromLua using the Serialize / Deserialize traits, and if so that might be a viable strategy to try?

from rlua.

zrkn avatar zrkn commented on August 19, 2024

There is a difference between ToLua/FromLua conversion path and Serialize/Deserialize, which can be a reason to keep them separate. ToLua/FromLua consumes self, when Serialize/Deserialize takes it by reference. Basically, first is conversion and second is serialization which are a bit different operations. End user can choose which is more appropriate for them.

from rlua.

kyren avatar kyren commented on August 19, 2024

Hmm, you're right, it's not really possible to combine them.

I'm not sure having that functionality in this crate is the right choice, would it be possible to have Serialize / Deserialize based Lua conversion as an external crate? Maybe you could have an extension trait on Lua that adds pack_serde and unpack_serde?

On a side note, I would eventually like to have some kind of ToLua / FromLua derive procedural macro.

from rlua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.