Add default_eq module

This commit is contained in:
Brendan Zabarauskas 2012-11-20 12:55:02 +10:00
parent 2d47523736
commit ef18db9f28
2 changed files with 25 additions and 0 deletions

View file

@ -31,6 +31,7 @@ pub mod common {
pub mod num {
pub mod cast;
pub mod consts;
pub mod default_eq;
pub mod ext;
}

24
src/num/default_eq.rs Normal file
View file

@ -0,0 +1,24 @@
use std::cmp::FuzzyEq;
pub trait DefaultEq {
pure fn default_eq(other: &self) -> bool;
}
pub impl bool: DefaultEq { #[inline(always)] pure fn default_eq(other: &bool) -> bool { self == *other } }
pub impl u8: DefaultEq { #[inline(always)] pure fn default_eq(other: &u8) -> bool { self == *other } }
pub impl u16: DefaultEq { #[inline(always)] pure fn default_eq(other: &u16) -> bool { self == *other } }
pub impl u32: DefaultEq { #[inline(always)] pure fn default_eq(other: &u32) -> bool { self == *other } }
pub impl u64: DefaultEq { #[inline(always)] pure fn default_eq(other: &u64) -> bool { self == *other } }
pub impl uint: DefaultEq { #[inline(always)] pure fn default_eq(other: &uint) -> bool { self == *other } }
pub impl i8: DefaultEq { #[inline(always)] pure fn default_eq(other: &i8) -> bool { self == *other } }
pub impl i16: DefaultEq { #[inline(always)] pure fn default_eq(other: &i16) -> bool { self == *other } }
pub impl i32: DefaultEq { #[inline(always)] pure fn default_eq(other: &i32) -> bool { self == *other } }
pub impl i64: DefaultEq { #[inline(always)] pure fn default_eq(other: &i64) -> bool { self == *other } }
pub impl int: DefaultEq { #[inline(always)] pure fn default_eq(other: &int) -> bool { self == *other } }
pub impl f32: DefaultEq { #[inline(always)] pure fn default_eq(other: &f32) -> bool { self.fuzzy_eq(other) } }
pub impl f64: DefaultEq { #[inline(always)] pure fn default_eq(other: &f64) -> bool { self.fuzzy_eq(other) } }
pub impl float: DefaultEq { #[inline(always)] pure fn default_eq(other: &float) -> bool { self.fuzzy_eq(other) } }