Skip to content
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

Use the num-traits crate directly instead of num #948

Merged
merged 2 commits into from Dec 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
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
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
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
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
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
@@ -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
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
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
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