mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.57k stars 213 forks source link

Integer values are limited by 2^63-1 (9223372036854775807). #332

Open BratSinot opened 2 years ago

BratSinot commented 2 years ago

Greetings!

Is there is a bug what integers are limited by 2^63-1?

use config::{Config, Environment, File, FileFormat};

fn main() {
    // Ok
    println!(
        "number: `{}`.",
        read_conf().get::<u64>("data.number").unwrap()
    );

    // Ok
    std::env::set_var("PREFIX_data.number", (1u64 << 63 - 1).to_string());
    println!(
        "number: `{}`.",
        read_conf().get::<u64>("data.number").unwrap()
    );

    // Error
    std::env::set_var("PREFIX_data.number", (1u64 << 63).to_string());
    println!(
        "number: `{}`.",
        read_conf().get::<u64>("data.number").unwrap_err()
    );
}

#[inline]
fn read_conf() -> Config {
    Config::builder()
        .add_source(File::from_str("[data]\nnumber = 1024", FileFormat::Toml))
        .add_source(Environment::with_prefix("PREFIX"))
        .build()
        .unwrap()
}
matthiasbeyer commented 2 years ago

Hi, thanks for opening this issue!

Could you add a testcase for this?

In https://github.com/mehcode/config-rs/pull/178/ we added support for u128 if I see that correctly, so maybe you just need to check for u128? I am also not 100% sure whether all formats support intergers of this size...

In any case, a testcase would be phenomenal! :+1:

BratSinot commented 2 years ago

Greetings!

Sorry for such long answer. Too much shit in the world happens lately.

Could you add a testcase for this? You mean for this case? I tried to look up in tests, but put that in back burner. If I get some free time, will happy to do that.