-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use a custom deserializer instead of wrapper types #6
Conversation
To document how I solved the The ITF trace deserialization to native types works as follows,
To get native deserialization of But this creates an weird issue - Note, with this, |
Note, this does not support
This is definitely feasible. But probably, not necessary as ITF doesn't include unsigned integers. |
We keep exporting it to allow for usecases where one needs the raw ITF `Value`, but avoid documenting it as there are a few pitfalls when doing so. See <#6 (comment)> for more information
itf/src/de.rs
Outdated
@@ -258,6 +258,7 @@ impl<'de> Deserializer<'de> for Value { | |||
{ | |||
match self { | |||
Value::BigInt(v) => visit_bigint(v, visitor), | |||
Value::Number(v) => visit_bigint(BigInt::new(v), visitor), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
@romac any idea why this (9920493) is not working? itf-rs/itf/tests/regression.rs Lines 141 to 154 in 9920493
Update: I realized why ! In this case, Line 120 in 9920493
IMO, this requires something like a |
…igInt` via `#[serde(deserialize_with = "...")]`
Ah good catch! Yeah it's a shame we can't seem to support this. That said, we can perhaps still enable this by providing a See a2eef53 What do you think? |
Yea Btw. I would prefer At impl<'de, T> serde_with::DeserializeAs<'de, T> for itf::value::BigInt
where
T: TryFrom<num_bigint::BigInt>
{ ... } Usage, use itf::value::BigInt;
use serde_with::As;
#[derive(Deserialize, Debug)]
enum FooBarWithInt {
Foo {
#[serde(with = "As::<Vec<Vec<BigInt>>>")]
_foo: Vec<Vec<i64>>,
},
Bar {
#[serde(with = "As::<HashMap<BigInt, BigInt>>")]
_bar: HashMap<i64, i64>,
},
} I can take care of the changes tomorrow 🙂 |
Ah good point, didn't think of containers! I am fine with adding |
I removed the code that implicitly serialized For Rust primitive integer types, a user has to explicitly use serde-with with |
Btw, |
Awesome! |
…out explicitly depending on `serde-with`
maybe it makes sense to redefine pub type Integer = TryFromInto<BigInt>; |
No description provided.