Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change images data field from Vec<u8> to Cow<'static, [u8]> #5837

Open
DrSloth opened this issue Aug 30, 2022 · 1 comment
Open

Change images data field from Vec<u8> to Cow<'static, [u8]> #5837

DrSloth opened this issue Aug 30, 2022 · 1 comment
Labels
A-Rendering Drawing game state to the screen C-Enhancement A new feature

Comments

@DrSloth
Copy link

DrSloth commented Aug 30, 2022

What problem does this solve or what need does it fill?

Distributing single binaries is really convenient and somnetimes a very efficient solution. The core question is wether the data field actually has to be a Vec<u8> or if it could be replaced with a Cow which spares memory allocation if the data is already inside the binary.

What solution would you like?

Optimally one would replace the data field with a Cow<'static, [u8]> and fits other functions that need to mutate the buffer to use Cow::to_mut

What alternative(s) have you considered?

This seems to be a rather "niche" case but it could add a lot of value, espacially for "default"/fallback textures.

Additional context

Generally loading Assets without the AssetServer is quite a hassle in my opinion, the documentation on how to create the assets could be improved or there could be a embedded assets asset server io based on rust_embed, but then there would also need to be an easy way to swap the AssetIo of the AssetServer.

@DrSloth DrSloth added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels Aug 30, 2022
@NathanSWard
Copy link
Contributor

Not sure if completely changing the underlying storage type permanently is the best route, however, possibly making it generic over the data type is another solution.
Especially if a Vec<u8> is the common use case, ideally not needing to pay for the extra overhead of a Cow<..> is likely preferred.

struct Image<T: AsRef<[u8]> = Vec<u8>> {
    data: T,
    ..
}

Granted this makes mixing Images with different data types a little more cumbersome.

@NathanSWard NathanSWard added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Enhancement A new feature
Projects
None yet
Development

No branches or pull requests

2 participants