-
Notifications
You must be signed in to change notification settings - Fork 73
Add reborrowing PixmapMut::as_mut #150
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
base: main
Are you sure you want to change the base?
Conversation
Also add PixmapRef::as_ref for parity
What is the use case for this? |
I was working on an API boundary, and ended up with a function signature that looked like:
which felt a bit redundant to me, as a This also allows for better ergonomics, as you can pass The most compelling piece of prior art (in my opinion) is |
There are no pointers in this code. Just references and they are zero cost in Rust, unless I'm missing something. The current expected approach is to use fn fill_path(pixmap: PixmapMut) {
pixmap.fill(Color::TRANSPARENT);
} |
But fn fill_path(mut pixmap: PixmapMut) {
pixmap.fill(Color::TRANSPARENT);
} would.
Unless the function is inlined, Rust references basically always compile down to pointers. So @robbie01 is indeed correct that it reduces the amount of indirection. It just likely won't last long as |
Good point. I don't remember why I have ended up using
That's strange. I thought that the only source of implicit indirection in Rust is trait objects. |
Ideally, we should follow some Rust API guidelines here, if there are any. I'm not sure what is "the correct" way of handling "mutable pointer wrappers". |
This allows you to get
PixmapMut
s all the way down, which can simplify structs and function signatures.This also adds
PixmapRef::as_ref
for parity, which is just aCopy
alias.