Implemented Ord and Eq

This commit is contained in:
Tony Aldridge
2014-03-09 11:22:59 +00:00
parent a92dfbd6f7
commit c55f3dc4aa
4 changed files with 58 additions and 16 deletions
+21
View File
@@ -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 {
+21
View File
@@ -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 {
+8 -7
View File
@@ -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 {
+8 -9
View File
@@ -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 {