Announcing the `resource` crate!


#1

https://crates.io/crates/resource

This is a crate for abstracting over loading/embedding resources.

So resource!("image.png") will expand to include_bytes!("image.png") in release mode, but in debug mode will actually load the file at runtime.

This is the second of my gamedev-slanted crates that I’ve been tuning up recently. I’ve found this really useful for avoiding file IO in the distributed executable, while allowing me to modify assets at runtime when developing.

This release also has some other nice features like loading multiple files, and post-processing files with a loading function.

I hope others find it useful!


#2

How are you determining the location to load from in debug mode?


#3

Currently, it’s relative to the CARGO_MANIFEST_DIR environment variable.

EDIT: For both static and dynamic loading. It should use the same path in both modes.


#4

Ah neat! I was looking for some mechanism like this but I couldn’t find anything that was stable across working directory of cargo invocation and workspace-enablement. CARGO_MANIFEST_DIR seems to always be an absolute path!


#5

Yep! Although now that you point it out, I can imagine times when you would want it to be a different/relative path.

I’ll think it over - might be able to implement something for the next version.

If you decide to give it a try, let me know if you run into any issues - feel free to open a ticket or anything :slight_smile: