remove impl ToColor for isize (#1473)

* remove `impl ToColor for isize`

- there is an impl for `u32` already, that impl is now the only one so
  rustc easily figures out the number type, that does not have to be
  explicitly annotated anymore.
- `isize` is not always wide enough to represent all colors. writing
  0xff0000ffisize compiles on 64 bit systems but not on 32 or 16 bit
  systems. (deny-by-default warning, if `allow`ed it will panic at
  runtime)

* update changelog
This commit is contained in:
Antoni Spaanderman
2025-03-27 23:11:54 +01:00
committed by GitHub
parent 829071af17
commit f0cdbb32b5
2 changed files with 3 additions and 17 deletions

View File

@@ -3,6 +3,8 @@ when upgrading from a version of rust-sdl2 to another.
### Next
[PR #1473](https://github.com/Rust-SDL2/rust-sdl2/pull/1473) **BREAKING CHANGE** Fix UB in `ToColor` implementations and remove implementation for `isize`.
[PR #1414](https://github.com/Rust-SDL2/rust-sdl2/pull/1414) Use `TTF_GlyphIsProvided32` and `TTF_GlyphMetrics32` instead of the 16 bit ones.
[PR #1435](https://github.com/Rust-SDL2/rust-sdl2/pull/1435) **BREAKING CHANGE** Fix some undefined behavior. Breaking changes: `mixer::Chunk`'s fields are now private and callbacks to `TimerSubsystem::add_timer` must now live for `'static`, also allowing some lifetime parameters to be removed.

View File

@@ -5,7 +5,6 @@ use libc::c_void;
use libc::{c_char, c_int};
use pixels;
use render::Canvas;
use std::convert::TryFrom;
use std::ffi::CString;
use std::ptr;
use surface::Surface;
@@ -36,6 +35,7 @@ impl ToColor for (u8, u8, u8, u8) {
}
}
// for 0xXXXXXXXX
impl ToColor for u32 {
#[inline]
fn as_rgba(&self) -> (u8, u8, u8, u8) {
@@ -49,22 +49,6 @@ impl ToColor for u32 {
}
}
// for 0xXXXXXXXX
impl ToColor for isize {
#[inline]
fn as_rgba(&self) -> (u8, u8, u8, u8) {
let [r, g, b, a] = u32::try_from(*self)
.expect("Can't convert to Color Type")
.to_be_bytes();
(r, g, b, a)
}
#[inline]
fn as_u32(&self) -> u32 {
u32::try_from(*self).expect("Can't convert to Color Type")
}
}
/// For drawing with rust-sdl2 Renderer
pub trait DrawRenderer {
fn pixel<C: ToColor>(&self, x: i16, y: i16, color: C) -> Result<(), String>;