Replace impl of Rows with ChunksExact#2942
Conversation
|
Another idea: Make Basically like this: #[derive(Copy, Clone, Debug, ...)]
pub struct Rows<'a, P> {
pixels: &'a [P],
width: u32,
}
impl Rows<'_, _> {
pub fn iter(&self) -> ChunksExact;
pub fn par_iter(&self) -> ParChunksExact;
pub fn get(&self, y: u32) -> Option<&[P]>;
}
impl IntoIterator for Rows;
impl Index<u32> for Rows;
// similar for RowsMutThis would grow the API surface, but enable us to (1) put all row-related functionality in one place and (2) add some functionality that would be harder to justify without. E.g. a user (or we) may need mutable access to 2 different rows. With Honestly, I'm not sure what the best API for |
|
Hm, providing |
Changes:
Rowsa type alias forChunksExact. Same for mut.After #2938,
Rowswas only a wrapper aroundChunksExact. In this PR I removed the wrapper and made it a type alias. At the cost of removing an abstraction (and having less control), I removed 150 LOC. This should also improve performance in some cases, sinceChunksExactimplements certain unstable traits and relies less on defaults. E.g.image.rows().nth(100)is now an efficient way to get the 100th row. Same for mut.I also contemplated removing the type aliases, since they are only used once.