Skip to content

remove impl ToColor for isize #1473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 1 addition & 17 deletions src/sdl2/gfx/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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>;
Expand Down
Loading