我有一个非常长的原始字符串文字。是否可以跨多行拆分它而不向字符串添加换行符?
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中做类似的事情?
答案 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);