Skip to content

Commit

Permalink
ColorStopsSource::collect_stops now consumes self
Browse files Browse the repository at this point in the history
This addresses a warning from pedantic lints about stops being
passed by `Gradient::with_stops` by value, but not consuming it.
  • Loading branch information
waywardmonkeys committed Dec 18, 2024
1 parent 0e0247e commit dd3cccc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This release has an [MSRV] of 1.82.

- `Image` now stores the alpha as an `f32` ([#65][] by [@waywardmonkeys][])
- Use `color` crate. See below for details ([#63][] by [@waywardmonkeys][])
- `ColorStopsSource::collect_stops` now consumes `self` ([#87][] by [@waywardmonkeys][])

### Removed

Expand Down Expand Up @@ -93,6 +94,7 @@ This release has an [MSRV] of 1.70.
[#72]: https://github.com/linebender/peniko/pull/72
[#77]: https://github.com/linebender/peniko/pull/77
[#82]: https://github.com/linebender/peniko/pull/82
[#87]: https://github.com/linebender/peniko/pull/87

[@dfrg]: https://github.com/dfrg
[@DJMcNab]: https://github.com/DJMcNab
Expand Down
22 changes: 11 additions & 11 deletions src/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ impl Gradient {
/// Trait for types that represent a source of color stops.
pub trait ColorStopsSource {
/// Append the stops represented within `self` into `stops`.
fn collect_stops(&self, stops: &mut ColorStops);
fn collect_stops(self, stops: &mut ColorStops);
}

impl<T> ColorStopsSource for &'_ [T]
where
T: Into<ColorStop> + Copy,
{
fn collect_stops(&self, stops: &mut ColorStops) {
for &stop in *self {
fn collect_stops(self, stops: &mut ColorStops) {
for &stop in self {
stops.push(stop.into());
}
}
Expand All @@ -350,15 +350,15 @@ impl<T, const N: usize> ColorStopsSource for [T; N]
where
T: Into<ColorStop> + Copy,
{
fn collect_stops(&self, stops: &mut ColorStops) {
for stop in *self {
fn collect_stops(self, stops: &mut ColorStops) {
for &stop in &self {
stops.push(stop.into());
}
}
}

impl<CS: ColorSpace> ColorStopsSource for &'_ [AlphaColor<CS>] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
if !self.is_empty() {
let denom = (self.len() - 1).max(1) as f32;
stops.extend(self.iter().enumerate().map(|(i, c)| ColorStop {
Expand All @@ -370,7 +370,7 @@ impl<CS: ColorSpace> ColorStopsSource for &'_ [AlphaColor<CS>] {
}

impl ColorStopsSource for &'_ [DynamicColor] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
if !self.is_empty() {
let denom = (self.len() - 1).max(1) as f32;
stops.extend(self.iter().enumerate().map(|(i, c)| ColorStop {
Expand All @@ -382,7 +382,7 @@ impl ColorStopsSource for &'_ [DynamicColor] {
}

impl<CS: ColorSpace> ColorStopsSource for &'_ [OpaqueColor<CS>] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
if !self.is_empty() {
let denom = (self.len() - 1).max(1) as f32;
stops.extend(self.iter().enumerate().map(|(i, c)| ColorStop {
Expand All @@ -394,17 +394,17 @@ impl<CS: ColorSpace> ColorStopsSource for &'_ [OpaqueColor<CS>] {
}

impl<const N: usize, CS: ColorSpace> ColorStopsSource for [AlphaColor<CS>; N] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
(&self[..]).collect_stops(stops);
}
}
impl<const N: usize> ColorStopsSource for [DynamicColor; N] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
(&self[..]).collect_stops(stops);
}
}
impl<const N: usize, CS: ColorSpace> ColorStopsSource for [OpaqueColor<CS>; N] {
fn collect_stops(&self, stops: &mut ColorStops) {
fn collect_stops(self, stops: &mut ColorStops) {
(&self[..]).collect_stops(stops);
}
}
Expand Down

0 comments on commit dd3cccc

Please sign in to comment.