From eb7ea5bec2e8a333f40d666fd58098aaa9820ce2 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Tue, 3 Dec 2019 19:30:45 +0200 Subject: [PATCH] Use the num-traits crate directly instead of num --- Cargo.toml | 5 +---- src/sdl2/audio.rs | 6 +++--- src/sdl2/event.rs | 2 +- src/sdl2/lib.rs | 2 +- src/sdl2/pixels.rs | 2 +- src/sdl2/render.rs | 2 +- src/sdl2/surface.rs | 2 +- src/sdl2/video.rs | 2 +- 8 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 256a173..1a89ea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 15d015f..861d92d 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -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; @@ -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); diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 304f5dc..6c9dfff 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -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; diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 1e0cf56..2e73de8 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -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] diff --git a/src/sdl2/pixels.rs b/src/sdl2/pixels.rs index 1b12351..be60677 100644 --- a/src/sdl2/pixels.rs +++ b/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; diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 24958e0..7804e0f 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -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}; diff --git a/src/sdl2/surface.rs b/src/sdl2/surface.rs index 93e98ed..3f7548d 100644 --- a/src/sdl2/surface.rs +++ b/src/sdl2/surface.rs @@ -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; diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index d1712c4..e0f9cbd 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -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;