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

fn resize: Make safe w/ WithOffset<PicOrBuf<AlignedVec64<u8>>> #1268

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Jun 28, 2024

This pattern can also be used in #1239 and can be used to resolve #1239 (comment).

@kkysen kkysen requested a review from randomPoison June 28, 2024 11:43
Base automatically changed from kkysen/struct-WithOffset-trait-Pixels-trait-Strided-enum-PicOrBuf to main July 1, 2024 20:32
Comment on lines +1011 to +1016
let dst = match dst.data {
PicOrBuf::Pic(pic) => &mut *pic.slice_mut::<BD, _>((dst.offset.., ..dst_w)),
PicOrBuf::Buf(buf) => &mut *buf.mut_slice_as((dst.offset.., ..dst_w)),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this logic into a slice_mut method on PicOrBuf? I expect that this pattern of matching on the enum and then doing the same slice operation on each variant would be a common usage of this type. If you don't add it in this PR I'd likely end up doing so in #1239.

Copy link
Collaborator Author

@kkysen kkysen Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because this uses lifetime extension and the guard types are not the same, only the lifetime extended slices from dereferencing the guards. Lifetime extension doesn't work through functions, so only a macro would work here, and I don't think that's worth it (Maybe it could? What do you think? Postfix macros would be nice here.). I tried a while to get this kind of thing to work until I realized that I'm pretty sure it's impossible. I guess a closure could also work, but that's unwieldy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I didn't catch that this was doing lifetime extension and that we had different guard types. So doing the match locally makes sense, I don't think a macro is worth it here

@kkysen kkysen merged commit 093a17d into main Jul 1, 2024
26 checks passed
@kkysen kkysen deleted the kkysen/fn-resize-safe branch July 1, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mc.rs: Unsafe cleanup
2 participants