相关疑难解决方法(0)

如何在Rust中编写多行字符串?

有可能写出类似的东西:

fn main() {
    let my_string: &str = "Testing for new lines \
                           might work like this?";
}
Run Code Online (Sandbox Code Playgroud)

rust

40
推荐指数
4
解决办法
1万
查看次数

在Rust中使用字符串文字更方便的连接

在每晚的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!"?

rust

10
推荐指数
2
解决办法
7923
查看次数

多行字符串文字语法

在许多语言中,多行字符串文字语法是

"""
Hello
World
"""
Run Code Online (Sandbox Code Playgroud)

但为什么它需要一个新的语法,为什么不使用"而不是"""?

喜欢:

"Hello
 World"
Run Code Online (Sandbox Code Playgroud)

language-agnostic

-2
推荐指数
1
解决办法
171
查看次数

标签 统计

rust ×2

language-agnostic ×1