fn prepend_code(src: &mut String, code: &str) {
    let insert_index =
        if let Some(preprocessor_index) = src.find("#version") {
            if let Some(newline_index) = src[preprocessor_index..].find('\n') {
                newline_index + preprocessor_index
            } else {
                // We might want to warn the user in this case. A shader with a
                // #version preprocessor but no newline will (I think) never
                // be valid, unless the code inserted here makes it valid
                src.len() 
            }
        } else {
            0
        };

    src.insert(insert_index, '\n');
    src.insert_str(insert_index + 1, code);
    src.insert(insert_index + 1 + code.len(), '\n');
}
/// Prepends the given section of code to the beginning of the given piece of
/// shader src. Note that code is inserted after the `#version ...`
/// preprocessor, if present.
Prepends the given section of code to the beginning of the given piece of
shader src. Note that code is inserted after the `#version ...`
preprocessor, if present.
Prepends the given section of code to the beginning of the given piece of shader src . Note that code is inserted after the ` #version ... ` preprocessor if present .
fn prepend_code(src: &mut String, code: &str) {
    let insert_index =
        if let Some(preprocessor_index) = src.find("#version") {
            if let Some(newline_index) = src[preprocessor_index..].find('\n') {
                newline_index + preprocessor_index
            } else {
                // We might want to warn the user in this case. A shader with a
                // #version preprocessor but no newline will (I think) never
                // be valid, unless the code inserted here makes it valid
                src.len() 
            }
        } else {
            0
        };
    src.insert(insert_index, '\n');
    src.insert_str(insert_index + 1, code);
    src.insert(insert_index + 1 + code.len(), '\n');
}
fn prepend_code ( src : & mut String , code : & str ) { let insert_index = if let Some ( preprocessor_index ) = src . find ( " " ) { if let Some ( newline_index ) = src [ preprocessor_index .. ] . find ( '\n' ) { newline_index + preprocessor_index } else { // We might want to warn the user in this case. A shader with a // #version preprocessor but no newline will (I think) never // be valid, unless the code inserted here makes it valid src . len ( ) } } else { 0 } ; src . insert ( insert_index , '\n' ) ; src . insert_str ( insert_index + 1 , code ) ; src . insert ( insert_index + 1 + code . len ( ) , '\n' ) ; }
Prepends the given section of code to the beginning of the given piece of
shader src.
Prepends the given section of code to the beginning of the given piece of shader src .
src
&mut String
code
&str
src
&mut String
code
&str