Is there a good way to include external resource data into Rust source code?

前端 未结 1 1866
深忆病人
深忆病人 2020-11-30 13:37

Imagine the following example:

let SHADER: &\'static str = \"
#version 140

attribute vec2 v_coord;
uniform sampler2D fbo_texture;
varying vec2 f_texcoor         


        
相关标签:
1条回答
  • 2020-11-30 14:19

    I believe you are looking for the include_str!() macro:

    static SHADER: &'static str = include_str!("shader.glsl");
    

    shader.glsl file should be located right beside the source file for this to work.

    There's also include_bytes!() for non-UTF-8 data:

    static SHADER: &'static [u8] = include_bytes!("main.rs");
    

    Don't conflate these with include!, which imports a file as Rust code.

    0 讨论(0)
提交回复
热议问题