Open
Description
Basically, this feels like an artifical restriction due to the fact that both str::as_bytes
and matching on byte strings is possible in constants:
const fn byte_string_workaround(x: &str) -> u8 {
match x.as_bytes() {
b"hello" | b"world" => 1,
b"goodbye" | b"nonworld" => 2,
_ => 3,
}
}
const fn string_failure(x: &str) -> u8 {
match x {
"hello" | "world" => 1,
"goodbye" | "nonworld" => 2,
_ => 3,
}
}
Note that byte_string_workaround
compiles fine on stable but string_failure
returns an error saying that strings can't be matched in constants.