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

add rkyv support #520

Merged
merged 2 commits into from
Jun 7, 2022
Merged

add rkyv support #520

merged 2 commits into from
Jun 7, 2022

Conversation

dovahcrow
Copy link
Contributor

This PR add optional rkyv support for Decimal.

Copy link
Owner

@paupino paupino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution - seems simple enough! There are a few additional changes to get this ready for merge:

  1. Can you add a test for this? Possibly follow the same style as borsh. You'd also need to add a new test into the Makefile and "turn it on" for CI here: https://github.com/paupino/rust-decimal/blob/master/Makefile.toml#L176
  2. Add a section to the readme for this feature. It doesn't have to be much! https://github.com/paupino/rust-decimal/blob/master/README.md#borsh
  3. Some minor tweaks as described in the Cargo.toml file in regards to default-features - it helps us keep build times low.

Cargo.toml Outdated
@@ -35,6 +35,7 @@ rocket = { default-features = false, optional = true, version = "0.5.0-rc.1" }
serde = { default-features = false, optional = true, version = "1.0" }
serde_json = { default-features = false, optional = true, version = "1.0" }
tokio-postgres = { default-features = false, optional = true, version = "0.7" }
rkyv = {version = "0.7", optional = true}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we do a couple of things here:

  1. this list is alphabetical - can we put it before rocket? The parameters are also alphabeticalized.
  2. Can we set default-features = false and include any required features explicitly?

@dovahcrow dovahcrow force-pushed the master branch 2 times, most recently from 9eec22f to dde70fb Compare June 7, 2022 03:45
@dovahcrow
Copy link
Contributor Author

@paupino Thank you for the detailed suggestions! I've revised the PR accordingly. This project is so well maintained! I appreciate all the time & effort you put on this project.

@dovahcrow
Copy link
Contributor Author

dovahcrow commented Jun 7, 2022

rkyv also allows one to use a safe api with a feature flag (https://github.com/rkyv/rkyv#example). Do you want to enable that by default?

FYI safe API allows one to deserialize types from bytes with some additional checks (e.g. byte alignment), with some performance sacrifice.

Copy link
Owner

@paupino paupino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change required with the feature flags (std isn't quite right).

rkyv also allows one to use a safe api with a feature flag (https://github.com/rkyv/rkyv#example). Do you want to enable that by default?

Your call! I'm happy with how it is right now but if you think it's a useful feature then feel free to add it.

Cargo.toml Outdated
@@ -68,7 +70,7 @@ serde-str = ["serde-with-str"]
serde-with-arbitrary-precision = ["serde", "serde_json/arbitrary_precision", "serde_json/std"]
serde-with-float = ["serde"]
serde-with-str = ["serde"]
std = []
std = ["rkyv/std"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right, but I see what you're trying to do. Perhaps for now, we can move the rkyv/std feature under rkyv also. It just means that the feature requires the std feature. I'll make a code suggestion for above.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std = ["rkyv/std"]
std = []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think std = ["rkyv/std"] means if the std feature of rust-decimal is turned on, also turn on the std feature of rkyv?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it includes the dependency by default too. See this section: https://doc.rust-lang.org/cargo/reference/features.html#dependency-features

I see that "rkyv?/std" is actually what we want however it requires a minimum rust version of 1.60. Unfortunately, it'll have to wait until the min version requirements catch up: https://github.com/paupino/rust-decimal#minimum-rust-compiler-version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. right "rkyv?/std" is the correct one.

Cargo.toml Outdated
@@ -59,6 +60,7 @@ default = ["serde", "std"]
legacy-ops = []
maths = []
maths-nopanic = ["maths"]
rkyv = ["rkyv/size_32"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rkyv = ["rkyv/size_32"]
rkyv = ["rkyv/size_32", "rkyv/std", "std"]

Copy link
Contributor Author

@dovahcrow dovahcrow Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rkyv can be used without std. I added rkyv/std in the std feature of rust_decimal

Oh I just saw your last comment.

@dovahcrow dovahcrow force-pushed the master branch 4 times, most recently from a55d9a1 to 61c06e6 Compare June 7, 2022 04:52
@dovahcrow
Copy link
Contributor Author

@paupino Fixed the std issue and also added safe API support via the rkyv-safe feature flag.

@paupino paupino merged commit 37764b7 into paupino:master Jun 7, 2022
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