I am trying to declare a const String in stable Rust but it does not let me declare it:
const CONSTANT_VALUE: String = String::from("constant value");
fn main() {
println!("{}", TARGET_PORT_KEY);
}
It is saying that:
Calls in constants are limited to tuple structs and tuple variants
I do not want to declare my string as literal and call to_string() on literal all the time.
What is the correct way to declare a constant String value?
Stringis a growable buffer. Its purpose is to be modifiable. Why would you pass around aStringif it's meant to be constant? Remember that API should usually take a&stras argument, not aString. The right constant type is&str.Stringparameters but it seems these parameters are immutable and constant as well so yes I can change them to&stras well. Thanks for clearing that out.Stringtype), it is better to take anInto<String>so that your API is more flexible.