How to declare a const String in stable Rust? [duplicate]

↘锁芯ラ 提交于 2020-02-24 12:06:12

问题


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?

Playground

来源:https://stackoverflow.com/questions/53932824/how-to-declare-a-const-string-in-stable-rust

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!