From 83d9789f65b6a19671c9fafbff15414094cacd8c Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 1 Nov 2021 00:01:52 +0100 Subject: [PATCH] Remove 'static bound from traits and impls The 'from traits' part is the breaking change. Downstream consumers could have previously made use of this additional bound. This is not required, we never utilize types `&'static [Subpixel]` or similar and if we would then it could be a local bound. But the bound is infectious in that it requires placing several additional bounds in every place where the `Pixel` trait is being used. --- src/buffer.rs | 42 +++++++++++++----------------------------- src/color.rs | 4 ++-- src/traits.rs | 4 ++-- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 78d659cb12..3368bf3086 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -614,13 +614,9 @@ pub struct ImageBuffer { } // generic implementation, shared along all image buffers -// -// TODO: Is the 'static bound on `I::Pixel` really required? Can we avoid it? Remember to remove -// the bounds on `imageops` in case this changes! impl ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref, { /// Contructs a buffer from a generic container @@ -830,8 +826,7 @@ where impl ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref + DerefMut, { // TODO: choose name under which to expose. @@ -921,7 +916,7 @@ where impl ImageBuffer where - P: Pixel + 'static, + P: Pixel, [P::Subpixel]: EncodableLayout, Container: Deref, { @@ -949,7 +944,7 @@ where impl ImageBuffer where - P: Pixel + 'static, + P: Pixel, [P::Subpixel]: EncodableLayout, Container: Deref, { @@ -977,7 +972,7 @@ where impl ImageBuffer where - P: Pixel + 'static, + P: Pixel, [P::Subpixel]: EncodableLayout, Container: Deref, { @@ -1023,8 +1018,7 @@ where impl Deref for ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref, { type Target = [P::Subpixel]; @@ -1036,8 +1030,7 @@ where impl DerefMut for ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref + DerefMut, { fn deref_mut(&mut self) -> &mut ::Target { @@ -1047,8 +1040,7 @@ where impl Index<(u32, u32)> for ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref, { type Output = P; @@ -1060,8 +1052,7 @@ where impl IndexMut<(u32, u32)> for ImageBuffer where - P: Pixel + 'static, - P::Subpixel: 'static, + P: Pixel, Container: Deref + DerefMut, { fn index_mut(&mut self, (x, y): (u32, u32)) -> &mut P { @@ -1086,9 +1077,8 @@ where impl GenericImageView for ImageBuffer where - P: Pixel + 'static, + P: Pixel, Container: Deref + Deref, - P::Subpixel: 'static, { type Pixel = P; type InnerImageView = Self; @@ -1119,9 +1109,8 @@ where impl GenericImage for ImageBuffer where - P: Pixel + 'static, + P: Pixel, Container: Deref + DerefMut, - P::Subpixel: 'static, { type InnerImage = Self; @@ -1191,10 +1180,7 @@ where // there is no such function as `into_vec`, whereas `into_raw` did work, and // `into_vec` is redundant anyway, because `into_raw` will give you the vector, // and it is more generic. -impl ImageBuffer> -where - P::Subpixel: 'static, -{ +impl ImageBuffer> { /// Creates a new image buffer based on a `Vec`. /// /// # Panics @@ -1306,13 +1292,11 @@ impl GrayImage { // TODO: Equality constraints are not yet supported in where clauses, when they // are, the T parameter should be removed in favor of ToType::Subpixel, which // will then be FromType::Subpixel. -impl<'a, 'b, Container, FromType: Pixel + 'static, ToType: Pixel + 'static> +impl<'a, 'b, Container, FromType: Pixel, ToType: Pixel> ConvertBuffer>> for ImageBuffer where Container: Deref, ToType: FromColor, - FromType::Subpixel: 'static, - ToType::Subpixel: 'static, { /// # Examples /// Convert RGB image to gray image. diff --git a/src/color.rs b/src/color.rs index 2be237f62e..1fe95961f3 100644 --- a/src/color.rs +++ b/src/color.rs @@ -219,7 +219,7 @@ $( // START Structure definitions #[allow(missing_docs)] pub struct $ident (pub [T; $channels]); -impl Pixel for $ident { +impl Pixel for $ident { type Subpixel = T; const CHANNEL_COUNT: u8 = $channels; @@ -347,7 +347,7 @@ impl IndexMut for $ident { } } -impl From<[T; $channels]> for $ident { +impl From<[T; $channels]> for $ident { fn from(c: [T; $channels]) -> Self { Self(c) } diff --git a/src/traits.rs b/src/traits.rs index 2533bb2ec2..ed826ae1b4 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -34,7 +34,7 @@ impl EncodableLayout for [f32] { /// The type of each channel in a pixel. For example, this can be `u8`, `u16`, `f32`. // TODO rename to `PixelComponent`? Split up into separate traits? Seal? -pub trait Primitive: Copy + NumCast + Num + PartialOrd + Clone + Bounded + 'static { +pub trait Primitive: Copy + NumCast + Num + PartialOrd + Clone + Bounded { /// The maximum value for this type of primitive within the context of color. /// For floats, the maximum is `1.0`, whereas the integer types inherit their usual maximum values. @@ -71,7 +71,7 @@ declare_primitive!(f64: (0.0)..1.0); /// An Enlargable::Larger value should be enough to calculate /// the sum (average) of a few hundred or thousand Enlargeable values. pub trait Enlargeable: Sized + Bounded + NumCast { - type Larger: Primitive + AddAssign + 'static; + type Larger: Primitive + AddAssign; fn clamp_from(n: Self::Larger) -> Self { // Note: Only unsigned value types supported.