acatton / serde-yaml-ng

Strongly typed YAML library for Rust, serde compatible. This is an independant continuation of serde-yaml from dtolnay.
MIT License
14 stars 1 forks source link

Can't convert integer value to Value struct. invalid type: integer `-9223372036854776000` as i128 #8

Open zhou-yi-git opened 1 week ago

zhou-yi-git commented 1 week ago

code:

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Demo {
    val_string: String,
    val_i128: i128,
    val: Value,
}
#[test]
fn test_serde_yaml() -> Result<(), serde_yaml::Error> {
    let yaml = "
        val_string: 123
        val_i128: -9223372036854776000
        val: -9223372036854776000
    ";
    let values: Demo = serde_yaml_ng::from_str(yaml).unwrap();
    Ok(())
}

output:

thread 'test_serde_yaml' panicked at src/main.rs:78:54:
called `Result::unwrap()` on an `Err` value: Error("val: invalid type: integer `-9223372036854776000` as i128, expected any YAML value", line: 4, column: 14)
acatton commented 1 week ago

There are multiple issues here:

I feel that this should be fixed the right way. Meaning we should be able to de-serialize a 128 bit integer. This involves a little bit of work, as I don't want to implement number as 128bit integer, therefore doubling the cost of numbers.

On the other side, if you don't need to de-serialize numbers that fit on more than 64 bits, we could do one of the two things:

Otherwise, I'll ask you to wait for when I find the time to refactor numbers.rs. What do you think?

zhou-yi-git commented 1 week ago

Alright, I believe the issue should be addressed properly, and I am prepared to wait for your solution. However, if you have the time to implement a quick fix in a new branch, and I can use it locally as a crate, it would be more beneficial.

zhou-yi-git commented 1 week ago

I did a quick and dirty fix as my local crate.