-
Notifications
You must be signed in to change notification settings - Fork 531
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
Add optional borsh serialization/deserialization #1366
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1366 +/- ##
==========================================
- Coverage 92.99% 92.93% -0.07%
==========================================
Files 34 34
Lines 16637 16648 +11
==========================================
Hits 15472 15472
- Misses 1165 1176 +11 ☔ View full report in Codecov by Sentry. |
Sorry, I am not interested in supporting yet another (de)serialization protocol at this time. |
@djc Do you have an alternative you suggest I do? I see borsh crate itself supports other crate serialisation behind feature flags so that's an option: much more hassle/less efficient because there's not access to any internals of course. It's a bit sad if that's the way it has to be considering the addition is just (in my eyes) few derives... |
If this is the case, should I open a ticket ala "remove all serialisation support and expose internals in some "internal" module to enable reimplementation by arbitrary crates"? This is a somewhat popular approach in the Haskell world I'm not trying to be malicious here, just trying to figure out how to proceed. |
I'm open to discussing changes that would be needed to enable you to implement this support outside the crate. Please make a minimal but comprehensive list. |
So far, I'm seeing:
I think those are the main pain points. There are more types (for example I'm not sure what an elegant Rust solution is to expose these things. Maybe a trait that's not imported by default that has methods to round-trip via Sadly, all of these seem more annoying to maintain, not less... I attach beginnings of a diff for support of |
Sorry to jump into an old discussion.
That is quite inefficient! The closest representation is getting the values with It does not help for serialization, but #1212 has the goal of removing the
Again, good point.
I suppose it can get a constructor. Like
We will get |
Supporting serde and rkyv is already proving quite a lot of work to be honest. Maybe we want to expose a method to get all values encoded in a Then we would only need an unsafe method to recreate the
|
With borsh as a format for 'security-critical projects' you may want to validate/recalculate the year flags anyway? Then I think the main missing item is an initializer for |
Is it? At a cursory glance, it looks like just automatic derives behind a feature flag. Same for the changes in this PR. Maybe there's some work I'm not seeing but this actually seems like the least amount of work possible for in-direct support and any other solution seems like more work, not less... At the moment we just use a chrono fork for our borsh experiment branch but it'd be nice if it Just Worked™ of course. |
With our release last week the number of features chrono has to support rkyv increased to 5 ( For serde it seems there always is another format that needs custom (de)serialization to a date or time. We have a whole bunch of issues and PRs. Maybe borsh will prove to be different and really only need 'automatic derives behind a feature flag', but I agree with @djc that at this time we need to use our time differently. What did you think about (de)serializing dates with year and ordinal values and the other suggested methods? Serializing is then just a couple of bit-wise masks and shifts. |
Going to close this to make it clear that direct inclusion of borsh support is not going to happen at this time. Happy to discuss more about extra API that we might provide to make it easier to do this out of crate, though! |
Sure, that's certainly better than the status quo. Though presumably the traits will need to go into |
Fell free to cc me on a PR to |
Another common option is an integration crate like borsh-chrono. For example, this is what we do with Askama and also for things like tokio-postgres-rustls. |
No description provided.