rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.9k stars 12.67k forks source link

Tracking issue for `FromStr` trait usage in const fn #59133

Open elichai opened 5 years ago

elichai commented 5 years ago

Because Rust already have macros that evaluate on compile time to strings I think converting them to ints in a const fn is a very nice feature.

e.g. env!("SOMETHING").parse::<usize>().unwrap()


I opened this Issue as part of: https://github.com/rust-lang/rust/issues/57563 Interested to hear if other people want this and if it's already exists as part of a different issue/RFC

jonas-schievink commented 3 years ago

Isn't this just https://github.com/rust-lang/rust/issues/67792 / rust-lang/rfcs#2632?

Skgland commented 5 months ago

It looks like the const_int_from_str feature, gate-ing the constness of the {integer}::from_str_radix associated method, also points here. Would it be possible to have that stabilized as it (as far as I can see/tell) does not depend on const trait?, unlike the constness of the FromStr trait (impls) this is otherwise about.

This would allow parsing ints at complie-time, e.g. from env!(), which I belive would help alot as that is the primary thing I find myself wanting to parse at compile-time.