Error E0015 occurs because Rust requires constant values to be computable at compile time, but you are calling a function that isn't marked as const inside a constant definition. To fix this, ensure the function you are calling is defined with the const keyword so the compiler can evaluate it during compilation.
const fn gives_ownership() -> String {
String::from("yours")
}
const MY_STRING: String = gives_ownership();
Note: As of current Rust versions, String cannot be created in a const context. You must use a &'static str instead.
const fn get_message() -> &'static str {
"yours"
}
const MY_STRING: &'static str = get_message();
If you cannot make the function const (e.g., it uses non-const features), you must move the logic out of the const definition and into a regular let variable inside a function like main.