toml-lang / toml

Tom's Obvious, Minimal Language
https://toml.io
MIT License
19.45k stars 847 forks source link

u64: number too large to fit in target type #964

Closed griffi-gh closed 1 year ago

griffi-gh commented 1 year ago

u64 fields only accept numbers that can fit into i64

Example 1

[world]
seed = 0xbeef_face_dead_cafe
thread 'main' panicked at 'Invalid configuration file: Error { inner: Error { inner: 
TomlError { message: "number too large to fit in target type", original: Some("[server]\naddress = \"0.0.0.0:12345\"\nmax_clients = 254\ntimeout_ms = 10000\n\n[world]\nseed = 0xaeef_face_dead_cafe\n"), keys: [], span: Some(88..89) } } }', kubi-server\src\config.rs:29:57

Example 2 (works)

[world]
seed = 0x0eef_face_dead_cafe
marzer commented 1 year ago

What programming language are you working in? This is the repository for the TOML language specification, not any particular implementation. Find the repository for your programming language's implementation and report your issue there.

(This isn't really a bug, though. TOML only mandates support for signed 64-bit integers. Support for anything out of that range is implementation-defined.)

griffi-gh commented 1 year ago

Yeah, sorry this is the wrong repo, i was looking for toml-rs/toml not toml-lang/toml

And also I didn't know that max integer size is defined by the standard.

marzer commented 1 year ago

And also I didn't know that max integer size is defined by the standard.

It's not the maximum, but actually the minimum; TOML integers must support the full signed i64 range. There's nothing in the spec saying they can't support numbers outside that range (e.g. u64, or 128-bit ints).

In practice though you'll find pretty much all implementations will just stick to i64 range so they don't create fragmentation, otherwise there can be situations where TOML exported from one environment can't be parsed in another.

There's a good discussion here if you want a bit more context.