我想在我的项目中嵌入一个图像文件。更准确地说,我想嵌入包含图像的已加载 Rust 对象,在我的例子中是 usvg::Tree
。 , 或更高级的 cairo::ImageSurface
.那可能吗?我只找到 String
的示例。
最佳答案
是的。
来自文档:
Includes a file as a reference to a byte array.
The file is located relative to the current file. (similarly to how modules are found)
This macro will yield an expression of type
&'static [u8; N]
which is the contents of the file.
数据类型没有限制。包括文字字节。值得一提的是,您需要确保字节对代码运行的平台有意义,并且您有某种解析字节的方法。
另见:
关于rust - include_bytes!() 可以用于自定义结构吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58921575/