Logan
Logan

Reputation: 1682

How to embed resources in Rust executable?

This is the cousin of this question over here asking the same thing for C.

Basically, is there a better way than to just turn it into a giant byte array and putting it in a source file?

Alternatively, does a macro have the ability to do this? (Rust Macros... are a dense looking and their exact capabilities are not known to me.)

Upvotes: 41

Views: 26781

Answers (2)

user1124403
user1124403

Reputation:

You could alternatively use this tool https://github.com/pyros2097/rust-embed Which was created by me which generates rust code for your resources.

Upvotes: 9

DK.
DK.

Reputation: 58975

You probably want include_bytes!.

If you are in older versions of Rust, use include_bin! instead.

Upvotes: 48

Related Questions