Skip to content
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

Serde support? #138

Open
d4h0 opened this issue Mar 22, 2023 · 4 comments
Open

Serde support? #138

d4h0 opened this issue Mar 22, 2023 · 4 comments

Comments

@d4h0
Copy link

d4h0 commented Mar 22, 2023

Hi,

(De-)serialization via serde would be a great addition to predicates.

This would be useful when a UI has filters which should be stored (so users don't have to setup the filters every time they open the application).

Or to send predicates between a server and a client.

@epage
Copy link
Contributor

epage commented Mar 22, 2023

To clarify, you are wanting the ability to serialize and deserialize predicates?

In theory, we could support this on some of the predicates, so long as they don't take a closure, etc but how would you plan to dispatch between the different predicates since a trait is being used. Would it be expected that the predicates project provides an enum encompassing built-in predicates (which seems like a dead end) or would users do that?

@d4h0
Copy link
Author

d4h0 commented Mar 23, 2023

To clarify, you are wanting the ability to serialize and deserialize predicates?

Yes, exactly. Basically, this would be similar to JsonLogic.

how would you plan to dispatch between the different predicates since a trait is being used. Would it be expected that the predicates project provides an enum encompassing built-in predicates (which seems like a dead end) or would users do that?

To be honest, I don't have any idea about any of this. I just had a cursory look at predicates to see whether I could use it, and thought it would be useful to suggest serde support, to enable more use-cases.

I thought it would be possible to just generate a serializable data structure, similar to JsonLogic, which can be deserialized back to a predicate.

In theory, we could support this on some of the predicates, so long as they don't take a closure

I've never used those crates, but maybe closures can be serialized via something like typetag or serde_traitobject.

For example, the creator of serde_traitobject also has the crate serde_closure.

@epage
Copy link
Contributor

epage commented Mar 23, 2023

First, I'll be upfront that this is not a priority for maintainers and this will likely only move forward by external contributors.

Second, some possible paths forward for this

  • You can experiment with this on your side by using serde's ability to add serialization support for foreign types
  • You could add an unstable-serde feature (ie all semver guarantees are out the window) and derive serde support for various predicates conditioned on the feature. You can then experiment on your side with how you want to handle dispatching which predicate is being deserialized.

@d4h0
Copy link
Author

d4h0 commented Mar 23, 2023

Thanks for the suggestions, @epage!

For my current project I decided to just hard code some predicates, but I might give this a try in the future.

Just to be clear: I never expected that this will be implemented quickly (or at all), but I thought it would be a useful addition, and that an open issue is a good way to see if other people are interested in this as well (via comments and other reactions).

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

No branches or pull requests

2 participants