Impl Copy, Clone for all types in common.rs #81
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a minor fix that allows to Copy and Clone all types in
src/framebuffer/common.rs
. More a minor thing to improve usability for some cases.I originally stumbled upon this when doing doomarkable. Wanted to specify the waveform depending on the device and later reuse it depending on the model in a render loop. Problem was that the variable in loop wouldn't work, since the parameter is owned and rusts ownership wouldn't permit me to give ownership repeatedly away in a loop (duh).
Wouldn't be a problem if the waveform mode could be cloned or such, but this wasn't derive. So I would basically need to create my own clone, remember it otherwise (basically serializing to a different type (e.g. and int) deserializing it again every time). My workaround was to just find out the same value every time in the loop while it would be perfectly fine to do once before the loop (any maybe use a clone on that value if not also Copy).
Clone would be enough, but those types are pretty primitive and surely not worth the cloning. Also more complex types in the same file already had also "Copy" specifies. So I took the liberty to ensure that all types in that file have Copy and Clone.
For the next version, looking that everything is at least Debug'able and (in most cases) at Clone'able would probably be good as well. Just wanted to to this quick fix now since that note sat on my todo list ever since.
Maybe those types should also get PartialEq, Eq and Hash as well in case people would need it. Not sure what Rust's philosophy would be in such a case (better to "over-derive" or "under-derive"?).