rust-lang/rust

Tracking issue for `FromStr` trait usage in const fn

elichai opened this issue · 2 comments

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: #57563
Interested to hear if other people want this and if it's already exists as part of a different issue/RFC

Isn't this just #67792 / rust-lang/rfcs#2632?

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.