Skip to content

Commit

Permalink
Merge pull request Rust-SDL2#948 from dmitmel/switch-to-num-traits
Browse files Browse the repository at this point in the history
 Use the num-traits crate directly instead of num
  • Loading branch information
Cobrand authored Dec 30, 2019
2 parents ad86713 + 8eeba21 commit cf540e1
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 16 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ path = "src/sdl2/lib.rs"
bitflags = "^1"
libc = "^0.2"
lazy_static = "^1"

[dependencies.num]
version = "^0.1"
default-features = false
num-traits = "^0.2"

[dependencies.sdl2-sys]
path = "sdl2-sys"
Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//! ```
use std::ffi::{CStr, CString};
use num::FromPrimitive;
use num_traits::FromPrimitive;
use libc::{c_int, c_void, c_char};
use std::ops::{Deref, DerefMut};
use std::path::Path;
Expand Down Expand Up @@ -810,13 +810,13 @@ impl AudioCVT {
//! the conversion in place; then it is passed to the SDL library.
//!
//! Certain conversions may cause buffer overflows. See AngryLawyer/rust-sdl2 issue #270.
use num::traits as num;
unsafe {
if self.raw.needed != 0 {
let mut raw = self.raw;

// calculate the size of the dst buffer
raw.len = num::cast(src.len()).expect("Buffer length overflow");
use std::convert::TryInto;
raw.len = src.len().try_into().expect("Buffer length overflow");
let dst_size = self.capacity(src.len());
let needed = dst_size - src.len();
src.reserve_exact(needed);
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Event Handling
use std::ffi::CStr;
use std::mem;
use libc::c_int;
use num::FromPrimitive;
use num_traits::FromPrimitive;
use std::ptr;
use std::borrow::ToOwned;
use std::iter::FromIterator;
Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/gfx/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::mem;
use std::ptr;
use std::ffi::CString;
use num::traits::ToPrimitive;
use std::convert::TryFrom;
use libc::{c_int, c_char};
use libc::c_void;
use render::Canvas;
Expand Down Expand Up @@ -57,12 +57,12 @@ impl ToColor for u32 {
impl ToColor for isize {
#[inline]
fn as_rgba(&self) -> (u8, u8, u8, u8) {
unsafe { mem::transmute(self.to_u32().expect("Can't convert to Color Type")) }
unsafe { mem::transmute(u32::try_from(*self).expect("Can't convert to Color Type")) }
}

#[inline]
fn as_u32(&self) -> u32 {
self.to_u32().expect("Can't convert to Color Type")
u32::try_from(*self).expect("Can't convert to Color Type")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#![allow(clippy::cast_lossless, clippy::transmute_ptr_to_ref)]

extern crate num;
extern crate num_traits;
pub extern crate libc;

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/pixels.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use num::FromPrimitive;
use num_traits::FromPrimitive;
use std::mem::transmute;
use std::convert::TryFrom;
use crate::sys;
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use libc::{c_int, c_double};
use crate::rect::Point;
use crate::rect::Rect;
use std::ffi::CStr;
use num::FromPrimitive;
use num_traits::FromPrimitive;
use std::vec::Vec;
use crate::common::{validate_int, IntegerOrSdlError};
use std::mem::{transmute, MaybeUninit};
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::rect::Rect;
use crate::get_error;
use std::ptr;
use libc::c_int;
use num::FromPrimitive;
use num_traits::FromPrimitive;
use crate::pixels;
use crate::render::{BlendMode, Canvas};
use crate::rwops::RWops;
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::surface::SurfaceRef;
use crate::pixels::PixelFormatEnum;
use crate::VideoSubsystem;
use crate::EventPump;
use num::FromPrimitive;
use num_traits::FromPrimitive;
use crate::common::{validate_int, IntegerOrSdlError};

use crate::get_error;
Expand Down

0 comments on commit cf540e1

Please sign in to comment.