What is the syntax for a multiline string literal?

后端 未结 5 1141
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 14:26

I\'m having a hard time figuring out how string syntax works in Rust. Specifically, I\'m trying to figure out how to make a multiple line string.

5条回答
  •  离开以前
    2020-12-12 14:46

    In case you want to do something a bit longer, which may or may not include quotes, backslashes, etc., use the raw string literal notation:

    let shader = r#"
        #version 330
    
        in vec4 v_color;
        out vec4 color;
    
        void main() {
            color = v_color;
        };
    "#;
    

    If you have sequences of double quotes and hash symbols within your string, you can denote an arbitrary number of hashes as a delimiter:

    let crazy_raw_string = r###"
        My fingers #"
        can#"#t stop "#"" hitting
        hash##"#
    "###;
    

提交回复
热议问题