有可能写出类似的东西:
fn main() {
let my_string: &str = "Testing for new lines \
might work like this?";
}
Run Code Online (Sandbox Code Playgroud) 在每晚的Rust中,不再可能将字符串文字指定为带有"〜"字符的 String .
例如,在C++中,我使用用户定义的文字连接字符串文字,而不是std::string每次都提到的外壳:
inline std::string operator"" _s (const char* str, size_t size) {return std::string (str, size);}
foo ("Hello, "_s + "world!");
Run Code Online (Sandbox Code Playgroud)
在Rust中是否存在类似的功能,以使字符串文字连接不那么痛苦String::from_str ("Hello, ") + "world!"?
在许多语言中,多行字符串文字语法是
"""
Hello
World
"""
Run Code Online (Sandbox Code Playgroud)
但为什么它需要一个新的语法,为什么不使用"而不是"""?
喜欢:
"Hello
World"
Run Code Online (Sandbox Code Playgroud)