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
Convert Pixel types into corresponding types from rgb crate. #1383
base: main
Are you sure you want to change the base?
Conversation
Interesting idea. Maybe we should deref into the types of the |
Worth pointing out that you can do Not thrilled that this would add more unsafe to the crate. I don't see anything unsound though as far as I can tell. |
8a9bef9
to
413e118
Compare
Pixel
structs to auto-deref into.
@HeroicKatora Done. |
413e118
to
318c358
Compare
Implements `Deref` targeting corresponding types from `rgb` crate. This allows their components to be accessed by name. For example, if `c` is `Rgb<u8>`, one can write `c.r` instead of `c.channels()[0]`. Implements `From<rgb::Ty> for image::Ty` bidirectionally.
318c358
to
75cf31a
Compare
4c7ed2c
to
2b39393
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an implementation perspective this PR has my approval. It's just that my experience with the technique of using Deref
like that is limited, so I do wonder if there is any stability concern that we're overlooking? A run of rustwide
against downstream crates might give more certain results, I've wanted to write some integration for this for a while now.
I was inspired by nalgebra crate, which uses |
I started looking at the code this generates and I'm starting to get worried this is too messy/confusing. After this change we'd have structs Rgb and RGB, crate rgb, enum variants Rgb8 and Rgb16, and type aliases RGB8 and RGB16. Yes, our pixel struct Rgb would transparently deref to RGB, but the reverse would require an into() call. To make matters worse, the change adds a couple methods to our pixel structs which return types from the rgb crate. The core issue is that Rust doesn't really support the ability to have multiple structs that can be used interchangeably. If we want to support nice field accesses, I think the right way to do it would be to commit to a breaking change. It would take more discussion but I do think a strong case could be made for adopting the standard rgb crate types outright (though perhaps wait for them to reach 1.0 first?). |
They have been on |
This is true if you have a value of |
Hmm, that is confusing. You'd be directed to the rgb crate's type if you click on "RGBA". I wonder if there's a way to hide all those methods though. The types from nalgebra that vector and point deref into have very few methods on them so they don't cause so much documentation noise. |
88d4a03
to
3d04dca
Compare
I added a commit that leaves the |
3d04dca
to
84dc002
Compare
This allows their components to be accessed by name. For example,
if
c
isRgb<u8>
, one can writec.r
instead ofc.channels()[0]
.I license past and future contributions under the dual MIT/Apache-2.0 license,
allowing licensees to chose either at their option.