-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding serde support(?) #1
Comments
Hi, interesting idea. I have not yet used serde before and I am open to implementing serde support. Just for my understanding, what is the benefit of serializing an instance of |
As far as I understand, there is nothing more. In my case, as a workaround, I did exactly as you said: Together with the It is not my case, but I would assume that, in distributed computing, when you pass serialized information around, re-parsing each time becomes a waste of time. This brings me to the trade-off you might want to think about. The implementation of serialization of
|
Thanks for your feedback. I will try it out. |
I experimented a little with serde and stumbled across the problem that function pointers cannot be serialized. |
Implementing custom serialization/deserialization for |
Thanks for looking into it!! Do you want to support closures that move values in the operators? If yes, then one can not use function pointers anymore, I found this discussion particularly helpful. To be more concrete, do you want to support the following? (based on exmex v0.8.2) use exmex::{parse, BinOp, Operator};
let v = 2;
let ops = [Operator {
repr: "*v",
bin_op: Some(BinOp {
apply: move |a: i32, b: i32| a * b * v,
prio: 1,
}),
unary_op: None,
}];
let to_be_parsed = "1 *v 1";
let expr = parse::<i32>(to_be_parsed, &ops)?;
assert_eq!(expr.eval(&[1])?, 2); In any way, when people want to store functions or closures, what I see is something like Changing all function pointers for serde_closure::structs::Fn feels a bit excessive (and I do not the performance drawbacks it would have). By the way, can one reconstruct the original expression from |
Thanks for your feedback. Interesting question. I like the simplicity of function pointers. If someone can make a strong case for closures that capture stuff from their surroundings, I will re-consider them. Regarding serialization, I currently think in the direction of unparsing and re-parsing. |
Sure, sounds fair :)
Just to be sure, how is the re-parsing done? I am thinking of the operators needed to parse the expression, as they are not in the expression, how is one going to parse it? If it is not possible, one might go for the following:
|
Yes. For re-parsing, one needs the operators.
All operators, custom or default, have the same type. Not sure how one could implement different serializations. |
Okay! I think we came to the conclusion that, to add serde support, one would need to change all function pointers for serde_closure::structs::Fn. With this, one could serialize the parsed expression together with operators (i.e. |
Do you have a use-case were re-parsing is too slow? Or can you think of one? |
I do not think it is a "common" case, but this is the closest to something useful I can think of. In short, "distributed recursive parsing", or "distributed tree construction". Say you have a really big expression to parse. Then, you would like to do the following:
|
Interesting use case. For the moment I have implemented just |
Nice! Thank you! |
Basic parse/unparse-serde-support added with Commit fc35d50. With the possibility to create partial derivatives which are again expression, expressions can be created differently than just parsing a string. This changed my mind to implement at least basic parse/unparse serde support for default operators. |
Basic support in Release |
Thanks a lot! |
Hi! Thank you for the crate!
I was wondering if you could add serde support, maybe through a feature flag.
I am using your crate and I am missing serde support for
FlatEx
.I noticed that you use
smallvec
. It has serde support through a feature flag, so it should be easy.Thanks beforehand!
The text was updated successfully, but these errors were encountered: