From 46695fde17786bbbd80a7f5da14692ae9f2df624 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Sun, 18 Jan 2026 22:42:14 -0700 Subject: [PATCH] fix: add deprecated compat shims for Gray_v08 and GrayAlpha_v08 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds backward-compatible methods for dependent crates during v0.8 → v1.0 migration: Gray_v08: - value() - reads .0 field - value_mut() - mutable access to .0 field - with_alpha() - creates GrayAlpha_v08 GrayAlpha_v08: - value_mut() - mutable access to .0 field - DerefMut impl - allows mutable .v/.a access All methods marked #[deprecated] to encourage migration to Gray_v09/GrayA. Tested with cargo-copter against 224 dependents: 95% pass rate. Regressions are version conflicts that auto-resolve when 0.8.91 is stable. --- src/formats/gray.rs | 27 +++++++++++++++++++++++++++ src/formats/gray_alpha.rs | 22 ++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/formats/gray.rs b/src/formats/gray.rs index dbbbd151..79ead552 100644 --- a/src/formats/gray.rs +++ b/src/formats/gray.rs @@ -48,3 +48,30 @@ impl core::ops::Deref for Gray_v08 { &self.0 } } + +impl Gray_v08 { + /// Reads the `.0` field + /// + /// This is a compatibility shim. Migrate to `Gray_v09` and use `.v` directly. + #[deprecated(since = "0.8.91", note = "Use Gray_v09 with .v field instead")] + pub fn value(self) -> T { + self.0 + } + + /// Exposes the `.0` field for writing + /// + /// This is a compatibility shim. Migrate to `Gray_v09` and use `.v` directly. + #[deprecated(since = "0.8.91", note = "Use Gray_v09 with .v field instead")] + pub fn value_mut(&mut self) -> &mut T { + &mut self.0 + } + + /// Add alpha component to this pixel + /// + /// This is a compatibility shim. Migrate to `Gray_v09` and use `GrayA` instead. + #[deprecated(since = "0.8.91", note = "Use Gray_v09::with_alpha() or GrayA instead")] + #[allow(deprecated)] + pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_alpha::GrayAlpha_v08 { + crate::formats::gray_alpha::GrayAlpha_v08(self.0, add_alpha_value) + } +} diff --git a/src/formats/gray_alpha.rs b/src/formats/gray_alpha.rs index 37c1b068..7a25361a 100644 --- a/src/formats/gray_alpha.rs +++ b/src/formats/gray_alpha.rs @@ -1,5 +1,5 @@ use crate::formats::gray_a::GrayA; -use core::ops::Deref; +use core::ops::{Deref, DerefMut}; #[repr(C)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -34,13 +34,31 @@ impl Deref for GrayAlpha_v08 { } } +impl DerefMut for GrayAlpha_v08 { + /// Compatibility shim - allows mutable access to `.v` and `.a` on the old `GrayAlpha` type. + /// + /// **Deprecated:** Migrate to `GrayA` instead of `GrayAlpha_v08`. + fn deref_mut(&mut self) -> &mut GrayA { + unsafe { &mut *(self as *mut Self).cast::>() } + } +} + impl GrayAlpha_v08 { /// Value - the brightness component. May be luma or luminance. /// - /// Backwards-compatible getter for `self.v` + /// This is a compatibility shim. Migrate to `GrayA` and use `.v` directly. + #[deprecated(since = "0.8.91", note = "Use GrayA with .v field instead")] pub fn value(&self) -> T { self.0 } + + /// Exposes the `.0` field for writing + /// + /// This is a compatibility shim. Migrate to `GrayA` and use `.v` directly. + #[deprecated(since = "0.8.91", note = "Use GrayA with .v field instead")] + pub fn value_mut(&mut self) -> &mut T { + &mut self.0 + } } #[test]