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

feat: introduce feature to limit integer to i64 #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vmx
Copy link
Member

@vmx vmx commented Sep 2, 2024

By default the IPLD Integer kind is represented internally as an i128. Serde has problems with untagged enums that contain i128 types. Therefore a feature flag called integer-max-i64 is introduced, which reduces the internal integer representation to i64.

This flag should be used with caution as e.g. not all valid DAG-CBOR data can now be represented.

Closes #19.

By default the IPLD Integer kind is represented internally as an `i128`. Serde
has problems with untagged enums that contain i128 types. Therefore a feature
flag called `integer-max-i64` is introduced, which reduces the internal integer
representation to `i64`.

This flag should be used with caution as e.g. not all valid DAG-CBOR data can
now be represented.

Closes #19.
Cargo.toml Outdated
@@ -20,6 +20,10 @@ serde = ["dep:serde", "dep:serde_bytes", "cid/serde"]
arb = ["dep:quickcheck", "cid/arb"]
# Enables support for the Codec trait, needs at least Rust 1.75
codec = []
# Makes the internal representation of an IPLD integer an `i64` instead of the default `i128`. This
# is usefult to work around Serde limitations in regards to untagged enums that contain `i128`
Copy link

Choose a reason for hiding this comment

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

typo?

-usefult
+useful

@Stebalien
Copy link
Contributor

One more thing to consider: Two feature flags that explicitly conflict at compile time with a compiler error.

  1. i128-integers enabled by default.
  2. i64-integers disabled by default.

That way, if someone pulls in the "default features", they'll never be surprised by someone else pulling in i64-integers.

@Stebalien
Copy link
Contributor

Note: I'd say that if neither feature is used, we should default to i128-integers (rather than just remove integer support...). Although I'd be happy to go either way.

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.

serde deserializer fails deserialize to untagged enums which has integer(i128) values
3 participants