如何在不将新行插入原始字符串的情况下包装原始字符串文字?

时间:2016-08-19 00:05:04

标签: string rust literals

我有一个非常长的原始字符串文字。是否可以跨多行拆分它而不向字符串添加换行符?

file.write(r#"This is an example of a line which is well over 100 characters in length. Id like to know if its possible to wrap it! Now some characters to justify using a raw string \foo\bar\baz :)"#)

例如,在Python和C中,您可以简单地将其写为多个字符串文字。

# "some string"
(r"some "
 r"string")

是否有可能在Rust中做类似的事情?

1 个答案:

答案 0 :(得分:15)

虽然原始字符串文字不支持此功能,但可以使用concat! macro

来实现
let a = concat!(
    r#"some very "#,
    r#"long string "#,
    r#"split over lines"#);

let b = r#"some very long string split over lines"#;
assert_eq!(a, b);
相关问题