mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Implemented Ord and Eq
This commit is contained in:
@@ -6,6 +6,27 @@ struct Key {
|
||||
code: uint,
|
||||
ident: &'static str,
|
||||
}
|
||||
|
||||
impl Ord for Key {
|
||||
fn lt (&self, other: &Key) -> bool {
|
||||
if self.code < other.code {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Key {
|
||||
fn eq (&self, other: &Key) -> bool {
|
||||
if self.code == other.code {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TotalOrd for Key {
|
||||
fn cmp(&self, other: &Key) -> Ordering {
|
||||
if self.code < other.code {
|
||||
|
||||
@@ -6,6 +6,27 @@ struct ScanCode {
|
||||
code: uint,
|
||||
ident: &'static str,
|
||||
}
|
||||
|
||||
impl Ord for ScanCode {
|
||||
fn lt (&self, other: &ScanCode) -> bool {
|
||||
if self.code < other.code {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for ScanCode {
|
||||
fn eq (&self, other: &ScanCode) -> bool {
|
||||
if self.code == other.code {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TotalOrd for ScanCode {
|
||||
fn cmp(&self, other: &ScanCode) -> Ordering {
|
||||
if self.code < other.code {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// This automatically generated file is used as sdl2::keycode.
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::hash::sip::SipState;
|
||||
|
||||
use std::num::FromPrimitive;
|
||||
use std::num::ToPrimitive;
|
||||
use std::to_bytes::IterBytes;
|
||||
|
||||
#[deriving(Eq)]
|
||||
pub enum KeyCode {
|
||||
@@ -245,12 +247,11 @@ pub enum KeyCode {
|
||||
|
||||
}
|
||||
|
||||
type Cb<'a> = 'a |buf: &[u8]| -> bool;
|
||||
impl IterBytes for KeyCode{
|
||||
|
||||
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
|
||||
self.code().iter_bytes(lsb0, f)
|
||||
}
|
||||
impl Hash for KeyCode {
|
||||
#[inline]
|
||||
fn hash(&self, state: &mut SipState) {
|
||||
self.code().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyCode {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// This automatically generated file is used as sdl2::scancode.
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::hash::sip::SipState;
|
||||
|
||||
use std::num::FromPrimitive;
|
||||
use std::num::ToPrimitive;
|
||||
use std::to_bytes::IterBytes;
|
||||
|
||||
#[deriving(Eq)]
|
||||
pub enum ScanCode {
|
||||
@@ -251,16 +253,13 @@ pub enum ScanCode {
|
||||
|
||||
}
|
||||
|
||||
|
||||
type Cb<'a> = 'a |buf: &[u8]| -> bool;
|
||||
impl IterBytes for ScanCode {
|
||||
|
||||
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
|
||||
self.code().iter_bytes(lsb0, f)
|
||||
}
|
||||
impl Hash for ScanCode {
|
||||
#[inline]
|
||||
fn hash(&self, state: &mut SipState) {
|
||||
self.code().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl ScanCode {
|
||||
/// Get the code
|
||||
pub fn code(&self) -> i32 {
|
||||
|
||||
Reference in New Issue
Block a user