1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
From 4d9e740dfd80df976d976e21a7e33fd9f8b3c362 Mon Sep 17 00:00:00 2001
From: Kostya Shishkov <kostya.shishkov@gmail.com>
Date: Fri, 22 Nov 2019 17:47:54 +0100
Subject: [PATCH 1/4] remove not really needed dependencies
---
Cargo.toml | 2 --
src/sdl/event.rs | 20 +++++++-------------
src/sdl/lib.rs | 2 --
src/sdl/video.rs | 8 --------
4 files changed, 7 insertions(+), 25 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index b53c715..ddf8523 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,6 +16,4 @@ name = "sdl"
path = "src/sdl/lib.rs"
[dependencies]
-num = "0.1.24"
-rand = "0.3"
libc = "0.1"
diff --git a/src/sdl/event.rs b/src/sdl/event.rs
index 17e2cff..12812f8 100644
--- a/src/sdl/event.rs
+++ b/src/sdl/event.rs
@@ -1,7 +1,6 @@
use std::mem;
use libc::c_int;
use std::slice;
-use num::FromPrimitive;
use std::ffi::CStr;
use std::str;
@@ -512,7 +511,7 @@ pub enum Key {
Last,
}
-impl FromPrimitive for Key {
+impl Key {
fn from_i64(n: i64) -> Option<Key> {
use self::Key::*;
@@ -753,11 +752,11 @@ impl FromPrimitive for Key {
})
}
- fn from_u64(n: u64) -> Option<Key> { FromPrimitive::from_i64(n as i64) }
+ fn from_u64(n: u64) -> Option<Key> { Self::from_i64(n as i64) }
}
fn wrap_key(i: ll::SDLKey) -> Option<Key> {
- FromPrimitive::from_usize(i as usize)
+ Key::from_u64(i as u64)
}
#[derive(PartialEq, Eq, Copy, Clone)]
@@ -829,7 +828,7 @@ pub enum Mouse {
WheelDown
}
-impl FromPrimitive for Mouse {
+impl Mouse {
fn from_i64(n: i64) -> Option<Mouse> {
Some(match n {
1 => Mouse::Left,
@@ -840,12 +839,10 @@ impl FromPrimitive for Mouse {
_ => return None,
})
}
-
- fn from_u64(n: u64) -> Option<Mouse> { FromPrimitive::from_i64(n as i64) }
}
fn wrap_mouse(bitflags: u8) -> Option<Mouse> {
- FromPrimitive::from_u8(bitflags)
+ Mouse::from_i64(bitflags as i64)
}
#[derive(PartialEq, Eq, Copy, Clone)]
@@ -903,7 +900,7 @@ fn wrap_event(raw: ll::SDL_Event) -> Event {
let ty = if ty.is_null() { return Event::None; }
else { *ty };
- let ty : EventType = match FromPrimitive::from_usize(ty as usize) {
+ let ty : EventType = match EventType::from_u64(ty as u64) {
Some(ty) => ty,
None => return Event::None
};
@@ -1022,9 +1019,6 @@ pub enum EventType {
impl EventType {
pub fn get_state(&self) -> bool { get_event_state(*self) }
pub fn set_state(&self, state: bool) { set_event_state(*self, state) }
-}
-
-impl FromPrimitive for EventType {
fn from_i64(n: i64) -> Option<EventType> {
Some(match n as ll::SDL_EventType {
ll::SDL_NOEVENT => EventType::None,
@@ -1048,7 +1042,7 @@ impl FromPrimitive for EventType {
})
}
- fn from_u64(n: u64) -> Option<EventType> { FromPrimitive::from_i64(n as i64) }
+ fn from_u64(n: u64) -> Option<EventType> { Self::from_i64(n as i64) }
}
pub fn pump_events() {
diff --git a/src/sdl/lib.rs b/src/sdl/lib.rs
index cf04157..0f2a910 100644
--- a/src/sdl/lib.rs
+++ b/src/sdl/lib.rs
@@ -1,8 +1,6 @@
#![allow(raw_pointer_derive)]
extern crate libc;
-extern crate rand;
-extern crate num;
pub use sdl::*;
diff --git a/src/sdl/video.rs b/src/sdl/video.rs
index 3f7020a..64084f8 100644
--- a/src/sdl/video.rs
+++ b/src/sdl/video.rs
@@ -1,7 +1,6 @@
use std::mem;
use libc::{c_int, c_float};
use std::ptr;
-use rand::Rng;
use std::slice;
use std::ffi::CString;
use std::path::Path;
@@ -305,13 +304,6 @@ pub enum Color {
RGBA(u8, u8, u8, u8)
}
-impl ::rand::Rand for Color {
- fn rand<R: ::rand::Rng>(rng: &mut R) -> Color {
- if rng.gen() { RGBA(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
- else { RGB(rng.gen(), rng.gen(), rng.gen()) }
- }
-}
-
impl Color {
pub fn from_mapped(bit: u32, fmt: *const ll::SDL_PixelFormat) -> Color {
let mut r = 0;
--
1.7.9.5
|