rust - include_bytes!() 可以用于自定义结构吗?

标签 rust

我想在我的项目中嵌入一个图像文件。更准确地说,我想嵌入包含图像的已加载 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/

相关文章:

oop - 为什么 Rust 不支持特征对象向上转换?

rust - 在rust中有多种返回类型

rust - 使用 Rust 会出现两个窗口,而不是一个

rust - 是否可以在调用 cargo build 时从命令行覆盖 Cargo.toml 中指定的 crate-type?

rust - 从通过迭代找到的 BTreeMap 或 BTreeSet 中删除项目

postgresql - Rust Actix-Web sqlx 可选功能 `time` 需要列 #4 ("created_at"的 TIMESTAMPTZ 类型)

rust - 我的最小函数有什么问题?

http - 如何在 Rust 中使用媒体文件正确格式化 HTTP 响应

rust - 如何在 Rust 中实现类似于 @override 的行为

json - 如何使用 serde_json 将 "NaN"反序列化为 `nan`?